S
H
A
R
E

Tuesday, August 02, 2011

Custom Form Appearance With Standard Behaviour

There are several ways to Custom Paint a form, but each has their flaw.
This method starts with a standard Form that has its BorderStyle set to None.


We also create a WindowMenu class which pops up in place of the standard WindowMenu. We do this because restoring the standard WindowMenu causes the standard Window Size options to be lost and these cannot be restored without adding the sizable border which we do not want to see.

To get the standard Size and Move options we simply create GraphicsPaths that react to the mouse in the same way as the standard Non-Client form parts do. To achieve this we simply intercept and manipulate a few standard Windows messages. For this article I have not used any Interop calls, but you may get more flexible results by using SendMessage() and SetMenuItemBitmaps() rather than sending WndProc() calls and OwnerDrawing the custom WindowMenu.

The example here simply paints the defined paths in order that you can physically see how this method works, it is not meant to be pretty. You are not restricted to where the paths are placed or what shape they are, you dont even have to stick to them exactly when painting, the paths are simply there for mouse interaction.
The only real problem with this method is that if you set AutoScroll to true then Scrollbars will appear on top of the fake NonClientArea. A simple fix for this is to dock a Panel to the form (set the forms margins as appropiate) and use this as the Form Client.

You'll need to add images to your projects resources for the buttons. You can download the images that I used here...

VB net Sample:



CSharp Sample:



by: Mick Dohertys'

0 comments:

Post a Comment