0

There are some programs such as Google Chrome and this: enter image description here

They have a windows forms border that is different than the default. How do these programs do this and still allow the user to drag the window around? Is it possible in C#?

MethodMan
  • 18,625
  • 6
  • 34
  • 52
Tiernan Watson
  • 313
  • 2
  • 12
  • 1
    I don't think either of those are Windows Forms applications. – stuartd Jan 25 '16 at 22:48
  • *Is it possible in C#?* - Sure, why not? – Joshua Shearer Jan 25 '16 at 22:49
  • 1
    Look into WM_NCPAINT and related messages to understand how it's done under the hood. https://msdn.microsoft.com/en-us/library/windows/desktop/dd145212%28v=vs.85%29.aspx - WPF _may_ have dedicated support for this; Windows Forms doesn't, you'd have to do it the old-school way. – xxbbcc Jan 25 '16 at 22:53
  • http://stackoverflow.com/questions/6329632/how-do-i-skin-my-winform-application - This SO link refers to skinning to be like office, but the same technique is used if you want it look like something else. – MutantNinjaCodeMonkey Jan 25 '16 at 22:53
  • Did you check these SO questions? [Remove the title bar in Windows Forms](http://stackoverflow.com/q/7482922/641833), [How to create a form with a border, but no title bar? (like volume control on Windows 7)](http://stackoverflow.com/questions/3594086/how-to-create-a-form-with-a-border-but-no-title-bar-like-volume-control-on-wi) – Trisped Jan 25 '16 at 22:57
  • could be done in `Angular JS` or `WPF` – MethodMan Jan 25 '16 at 22:58

1 Answers1

2

There are plenty of component suites (DevExpress, Infragistics, Telerik, etc.) doing this but you can do it on your own as well. But prepare to get dirty - really dirty!

Basically you have to catch the windows messages (yes, native!) and handle them properly. To make the form draggable is the easiest thing in this chapter (you just have to tell windows that the mouse is over the titlebar area even if it is not >> see here on CodeProject).

Let me get back to the painting: Don't do it!

There are so many things to handle ...

  • is your form maximized, minimized, normal state
  • which of the buttons (min/max/close) are enabled?
  • is it a tool window or a sizeable one?
  • is there a help button?
  • is the form sizeable? if so, you have to draw that border as well ...

... and so many more.

In addition, painting in the non-client-area is not as easy as painting usercontrols with a Graphics object. And even if that does not scare you by now, you might probably find yourself breaking the layouting logic of your forms' controls because the forms' size is the same as its ClientSize.

So, please consider to use DevExpress or any other toolkit. Speaking of DevExpress - I knew there was a free set of their fantastic controls and I'm pretty sure that the XtraForm (which does all the titlebar painting) is included as well.

Save big parts of your life and skip that chapter.

(However, if you're brave enough, check this article to do it anyway).

Waescher
  • 5,361
  • 3
  • 34
  • 51