Copyright © 2003-2010 MultiMedia Soft

How to change the shape of my forms

Previous pageReturn to chapter overviewNext page

In order to provide support for the creation of skinned and graphical-rich applications, you can use the built-in Ctl3dFormShaper control. As you will see, its use is very straightforward.

From the components Toolbox, drag & drop the Ctl3dFormShaper control into the form you want to shape.


The following icon will appear inside the form


Select the icon above and, from the Properties pane, enter a picture that will determine the form shape into the ShapePicture property. On the picture below you can see the properties involved with form shaping


The TransparentColor property and the EnableFormShape property, pointed on the picture above, shouldn't need to be modified from their default value.

The picture below, courtesy of Microsoft Windows Media Player, demonstrates how the picture must be setup in order to be used as a shape mask


As you can see on the picture above, the main shape is surrounded by a color that doesn't appear inside the main shape: this will allow the control to render this color as transparent: if you should render as transparent another of the colors inside the picture, you should change the TransparentColor property.

Run the form and see the result on the picture below where the form appears in transparency over the PC desktop:


From the picture above, you can see the exceptional side effect of using this control in order to change the shape of your form: it automatically will set the picture mask opaque area as background of your shaped form, without the need to setup this feature in a second stage. One single picture for two different purposes.

If you need to temporarily disable the form shaping and revert back to the classical rectangular shape, just set to False the EnableFormShape property.

As you can see on the picture above, for esthetical reasons, shaped forms loose their caption bar so the problem we have to face now is how to move the form position around the desktop using mouse dragging. A very simple technique to solve this issue is to override the WndProc function of your form, as displayed on the picture below:


From inside the WndProc function, we need to intercept the WM_LBUTTONDOWN Windows message (hex value 0x0201), leaving our Ctl3dFormShaper control do the rest through the call to its MoveShapedForm method.

Below you can find two code snippets, written in VB.NET and C#, that demonstrate how easy is this task:


[Visual Basic]

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

 If m.Msg = &H201& Then

    Ctl3dFormShaper1.MoveShapedForm(Me.Handle.ToInt32(), m.LParam.ToInt32())


 End If


End Sub




protected override void WndProc (ref Message m)


if (m.Msg == 0x0201)


ctl3dFormShaper1.MoveShapedForm ((int) this.Handle, (int)m.LParam);



base.WndProc(ref m);