Monday, January 11, 2010

Creating Non-Rectangular Form in C#

Hello Friends,


Now here i am trying some very good stuff on C#.net.
The first in this row is creating non rectangular Form in C#.

The Idea comes when i was created Magnifier as a sub part of my project.
When i created a rectangular magnifier it's ok but when it comes to rounded then
i have to think.

From some book i get these idea (also available in many of GDI tutorials).

The idea behind this is that, GDI provides a new Class called GraphicsPath.
With the help of this class you can draw any closed arc, lines and shapes.

So either override onPaint event of form or Onload event put some code stuff like this.


System.Drawing.Drawing2D.GraphicsPath myShape = new System.Drawing.Drawing2D.GraphicsPath();
myShape.AddEllipse(0, 0, this.Width, this.Height);
this.Region = new System.Drawing.Region(shape);

Note:- You are not getting region property directly in intellisence because it is the
property of control class and here this refers the control.

Now in place of AddEllipse you can add any closed shape for your form.
Hope you enjoy....

No comments:

Post a Comment