|
-
August 28th, 2009, 09:19 AM
#1
Change the shape of the form in C#
I want to have a form with the shape of a rectangle with rounded corners..
I have found just how to change it to ellipse form..
Thanks!
-
August 28th, 2009, 03:31 PM
#2
Re: Change the shape of the form in C#
 Originally Posted by Gbates
I have found just how to change it to ellipse form..
Well that is the same way you change it to rectangle. Just change the image that you are using. It shouldn't be difficult.
By the way, welcome to the forum
-
August 29th, 2009, 05:32 AM
#3
Re: Change the shape of the form in C#
I didn't use an image, I used a code.
thanks :P
how do I change it with an image?
-
August 29th, 2009, 09:20 AM
#4
Re: Change the shape of the form in C#
Show us what code have you used.
-
August 30th, 2009, 09:38 AM
#5
Re: Change the shape of the form in C#
protected override void OnPaint( System.Windows.Forms.PaintEventArgs e )
{
System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath();
shape.AddEllipse(0, 0, this.Width, this.Height);
this.Region = new System.Drawing.Region(shape);
}
-
August 30th, 2009, 02:24 PM
#6
Re: Change the shape of the form in C#
You can use Shape.AddRectangle to give it a rectangular look. Or you can use a more easier solution.
Create the desired image in Paintbrush or a similar application. On the form, set the BackgroundImage property to the new Image that you created. Set the TransparencyKey property to white and FormBorderStyle to none. That is all that you would need to do.
-
August 31st, 2009, 05:30 AM
#7
Re: Change the shape of the form in C#
for one corner i calculated the coordination and made the upper left corner round-shaped; you can calculate yourself coordination for other three corners and then make them look rounded just adding a few lines of code to my code. just remember to change my coordination when you add other coordination for other three corners.
Code:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath();
Rectangle rect = new Rectangle(50, 0, this.Width, this.Height);
Rectangle rect2 = new Rectangle(0, 50, 50, this.Height);
shape.AddPie(0, 0, 100, 100, -90, -90);
shape.AddRectangle(rect);
shape.AddRectangle(rect2);
this.Region = new System.Drawing.Region(shape);
}
Please rate my post if it was helpful for you.  Java, C#, C++, PHP, ASP.NET
SQL Server, MySQL
DirectX
MATH Touraj Ebrahimi
[toraj_e] [at] [yahoo] [dot] [com]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|