S
H
A
R
E

Sunday, July 31, 2011

Shaped Form Resizable and Moveable

Shaped Form Resizable and Moveable
This is by no means a complete solution, just an idea for creating custom shaped forms with custom Titlebars.
The form can be dragged by its fake titlebar, and if right clicked the fake Titlebar will popup the WindowMenu.
The CreateParams property has been modified to add a System Menu (with Min,Move and Close items) to a borderless form.

The Titlebar button are not controls, they are simply drawn in the fake title bar and they react to hittesting.
The MainMenu is actually labels that popup Contextmenus.
The form can be resized only by its resizegrip, but you could define regions for each of the sides and corners and allow sizing by dragging the edge. The example requires a little work to be useable, but it should give you an idea of how to achieve this solution.
With a little InterOp you can draw a standard TitleBar onto which you can place custom buttons, and this solution is much simpler than that of OwnerDrawing the NonClient Area to achieve the same effect.

VB net Sample:



CSharp Sample:



by: Mick Dohertys'

1 comments:

Robert Dancso said...

Hello

This is a very good solution for shaped form! Much more better than if we use the 'transparency key'. With that the form cannot visible with screenshot tools on XP.
Thank you for the code.

Post a Comment