Winforms - How do I create a custom windows border and close/minimise buttons?

Brian Lyttle picture Brian Lyttle · Nov 20, 2008 · Viewed 34.2k times · Source

I would like to be able to create a black custom window (with border and controls) like that shipped as part of expression blend, Twirl, or Adobe Lightroom.

How do I create an owner-drawn window?

Answer

MusiGenesis picture MusiGenesis · Nov 20, 2008

If the custom-chrome tools don't provide you with the look-and-feel that you want, this kind of thing is easy to do yourself in C#. Basically, you create a borderless form (FormBorderStyle = None) and then create all the controls and borders yourself, by placing controls where you need them (a label for the title bar, command buttons for close and minimize etc.) and/or drawing directly on the form's surface using the Graphics object.

You also have to implement code to allow the form to be dragged around by its "fake" title bar (see this answer for a sample of how to do this). You may also have to implement your own resizing mechanism (if you need the forms to be resizable).

Finally, although the custom-form code might be a bit clunky, you can implement it on a single form and then have all the other forms in your application inherit from this form, which makes it a very useful technique for custom-skinning an entire application.