how can i make a circular form by using c#

Dani AI

Generated

Short answer for : drawing an ellipse with DrawEllipse (as did) only paints pixels — it does not change the form's hit test area or shape. To make the window itself circular, remove the border/title bar and give the form a circular Region. 's shapes snippet points the right way.

A minimal, robust pattern is:

  • remove the chrome (set FormBorderStyle = FormBorderStyle.None),
  • build an elliptical GraphicsPath sized to the form client area,
  • assign that path to the form Region,
  • and recompute the region on resize.

Example (place in the form class):

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    FormBorderStyle = FormBorderStyle.None;
    using (var gp = new System.Drawing.Drawing2D.GraphicsPath())
    {
        gp.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height);
        Region = new System.Drawing.Region(gp);
    }
}

protected override void OnResize(EventArgs e)
{
    base.OnResize(e);
    using (var gp = new System.Drawing.Drawing2D.GraphicsPath())
    {
        gp.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height);
        Region = new System.Drawing.Region(gp);
    }
}

Troubleshooting and tips:

  • Recompute the region in OnResize so the circle stays correct when the form is resized.
  • Put persistent drawing in OnPaint; avoid CreateGraphics for anything that must persist. See the Control.CreateGraphics guidance.
  • Regions clip child controls — lay out controls entirely inside the circular area.
  • Removing the title bar removes built-in dragging; implement window dragging yourself (mouse handling or a small WM_NCHITTEST/SendMessage trick).
  • For API details see the Form.Region property and GraphicsPath.AddEllipse docs: and GraphicsPath.AddEllipse.

Recommended Answers

All 2 Replies

Hi

Graphics g = this.CreateGraphics();
  Pen pen = new Pen(Color.Red, 2);
  g.DrawEllipse(pen, 20, 14, 20, 20);

Regards,
Camilo

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.