How do i dynamically removing/adding(cancel the removal) form area using region and graphics path class
Asked
Active
Viewed 393 times
0
-
@Suriyan: You really should put more effort into asking your question, if you want someone to answer it. – Jørn Schou-Rode Apr 03 '10 at 12:51
1 Answers
0
To change the shape of your Form dynamically, just set the Region
property of the form to a new Region
object created from a GraphicsPath
. For example, a form with a single button on it could change it's shape like this: (working example)
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace Sample
{
public class ShapedForm : Form
{
Button testbutton;
public ShapedForm()
{
// Create a button.
testbutton = new Button();
testbutton.Location = new Point(10, 10);
testbutton.Size = new Size(50, 50);
testbutton.Text = "Click me!";
testbutton.Click += new EventHandler(this.testbutton_Click);
this.Controls.Add(testbutton);
// Remove the border around the form.
this.FormBorderStyle = FormBorderStyle.None;
// Set the initial shape of the form to an ellipse.
GraphicsPath path = new GraphicsPath();
path.AddEllipse(0, 0, 200, 100);
this.Region = new Region(path);
}
private void testbutton_Click(object sender, EventArgs e)
{
// Change the shape of the form to some other ellipse.
GraphicsPath path = new GraphicsPath();
path.AddEllipse(0, 0, 100, 100);
path.AddEllipse(120, 40, 50, 50);
this.Region = new Region(path);
}
}
}

Daniel A.A. Pelsmaeker
- 47,471
- 20
- 111
- 157
-
thanks for your answer. i think, i couldn't rollback to its original state once removed. your answer is pretty straight – Suriyan Suresh Apr 04 '10 at 09:15