user366312
user366312

Reputation: 17026

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

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);

        }
    }

Upvotes: 2

Views: 880

Answers (2)

Lucero
Lucero

Reputation: 60276

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.

Upvotes: 4

Johann Blais
Johann Blais

Reputation: 9469

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

Upvotes: 0

Related Questions