Create a Circle shaped Form using Regions


This article represent code snippet for Create a Circle shaped Form using Regions in winforms controls

The “Region” property is used to apply the custom shape for the control. Here’s the example to create a form in round shape. This is very help full to create a high graphical user interface.

OnPaint event internally using the Region property, if the region property of the control is not null it will paint only the region area, its skipping other areas to paint.



public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
Form f = new Form();
f.Height = 350;
f.Width= 350;

//Creating circle path
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddEllipse(0, 0, 300, 300);

//Creating the region from the circle path
f.Region = new Region(path);

f.Show();
}
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: