Home > other >  How can I draw a filleeliipse on pictureBox corners?
How can I draw a filleeliipse on pictureBox corners?

Time:10-22

I'm trying to draw one ellipse at 0,0 and it's working but on the other side at pictureBox1.Width it's not drawing anything :

private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.FillEllipse(Brushes.Purple, 0, 0, 5, 5);
            e.Graphics.FillEllipse(Brushes.Purple, pictureBox1.Width, 0, 5, 5);
        }

The result is one ellipse filled on the left side at 0,0 but on the right side nothing. There should be small purple point also near the right yellow one.

enter image description here

And then to draw filled ellipse on all the 4 corners on the pictureBox1.

CodePudding user response:

The result is one ellipse filled on the left side at 0,0 but on the right side nothing. There should be small purple point also near the right yellow one.

This is because it's off the screen a bit, you'll need to adjust the X coordinate.

 e.Graphics.FillEllipse(Brushes.Purple, pictureBox1.Width - 5, 0, 5, 5);

enter image description here

If you'd like all four corners:

 int circleSize = 5;

 e.Graphics.FillEllipse(Brushes.Purple, 0, 0, circleSize, circleSize); //top left
 e.Graphics.FillEllipse(Brushes.Purple, pictureBox1.Width - circleSize, 0, circleSize, circleSize); //top right
 e.Graphics.FillEllipse(Brushes.Purple, pictureBox1.Width - circleSize, pictureBox1.Height - circleSize, circleSize, circleSize); //bottom right
 e.Graphics.FillEllipse(Brushes.Purple, 0, pictureBox1.Height - circleSize, circleSize, circleSize); //bottom left
  • Related