Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I create non-rectangular forms?

Check out this MSDN Library article Shaped Windows Forms and Controls in Visual Studio .NET by Seth Grossman of the Visual Studio Team.

There are two ways to create non-rectangular windows.

The first way is to change the Control.Region property, which, of course is inherited by Form.

[C#]

GraphicsPath gp = new GraphicsPath(); 
gp.AddEllipse( 0, 0, 100, 100 ); 
gp.AddRectangle( 50, 50, 100, 100); 
this.Region = new Region( gp ); 

[Visual Basic]

Dim gp As New GraphicsPath() 
gp.AddEllipse(0, 0, 100, 100) 
gp.AddRectangle(50, 50, 100, 100) 
Me.Region = New [Region](gp) 

The second way is to use the Form.TransparencyKey property. This tells the form not to paint any pixels that match the color of the TransparencyKey. So you can make your fancy skin bitmap, then set the TransparencyKey to be, say Color.Red, then all the pixels that are RGB(255,0,0) will be transparent.

Shawn Burke, Microsoft



Page view counter