Click here to Skip to main content
15,887,297 members
Articles / Programming Languages / C#
Tip/Trick

Resize form using GraphicsPath

Rate me:
Please Sign up or sign in to vote.
3.67/5 (2 votes)
23 Jul 2012CPOL 12.8K   246   3   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.

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
nobodyxxxxx20-Jul-12 3:58
nobodyxxxxx20-Jul-12 3:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.