Introduction
This piece of code will convert our Windows form from this rectangular shape
to an elliptical shape like this.
Background
Once I was going through the properties of my form through MSDN. I just happened to come
across region
property of my form.
Then I did something funny I tried to change the shape of my form.
Using the code
To accomplish this task I have used GraphicsPath
class from using System.Drawing.Drawing2D
namespace.
To change shape of my form initially I have to change my region of my form.
Form's region
property accepts a value of Region
class.
Region
class accepts an object of GraphicsPath
class.
So first I created an object of GraphicsPath
class. Then I
added an ellipse using my object of my GraphicsPath
, gp
. After that I create an object of Region which accepts a parameter of my
GraphicsPath
. Now I have to just pass my reg
to my forms region property.
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(50, 50, 200, 100);
Region reg = new Region(gp);
this.Region = reg;
this.BackColor = Color.Maroon;
You can try with different shapes in GraphicsPath
. Now go ahead and try resizing forms as per your wish.
Happy resizing.