Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Resize form using GraphicsPath

0.00/5 (No votes)
23 Jul 2012 1  
This code will help us to reshape our Windows form.

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here