tags:

views:

43

answers:

2

How to draw a circle on a form that covers the whole working area?

I have tried the following code. But when I re-size the form, the circle is distorted. alt text

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

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            Pen redPen = new Pen(Color.Red, 3);
            Rectangle rect = new Rectangle(0,0, this.ClientSize.Width, this.ClientSize.Height);

            g.DrawEllipse(redPen, rect);

        }
    }
A: 

Try to set the DoubleBuffered property of the Form to true.

Johann Blais
+4  A: 

You should hook into the ClientSizeChanged event as well to trigger a redraw.

What currently happens is that Windows assumes that only the small portion which became visible needs to be redrawn, and clips everything else off. You therefore need to invalidate the full form (Invalidate()) when a resize takes place.

If the circle starts flickering when resizing, enable double buffering of the form.

Lucero