Drawing ellipses question  
Author Message
Foolios





PostPosted: Visual C# General, Drawing ellipses question Top

I am drawing a yellow circle but realized I have a problem with it.
Graphics g = e.Graphics;

Pen yellow = new Pen(Color.Yellow, 3);

g.DrawEllipse(yellow, 100, 50, 100, 60);

I thought that this was centering the circle in the form at (100,50) while making it's horizontal diameter 100 and it's vertical diamater 60, but I am not sure if this is correct. It appears from what I have read is that the int x, int y positions are for the beginning of the rectangle that forms the bounds of this ellipse. Does this mean that this is the center of my circle or just like drawing a rectangle, it is the beginning from the top left location I want my ellipse centered at 100,50. Is this right What should it look like if it's not


Visual C#13  
 
 
David L





PostPosted: Visual C# General, Drawing ellipses question Top

g.DrawRectangle(yellow, 100, 50, 100, 60);

g.DrawEllipse(yellow, 100, 50, 100, 60);

The code above would produce a rectangle with cordinates (100, 50) having a width of 100 and a height of 60. The ellipse will fit perfectly in this rectangle. In other words, the cordinates (x, y) of an ellipse is not the center of it, but rather its top, left placing.

If you'd want an ellipse centered at (100, 50) you'd simply have to to substract half of its width from x, and half of its height from y.

int x = 100;

int y = 50;

int width = 100;

int height = 60;

g.DrawEllipse(yellow, x-width/2, y-height/2, width, height);

Did that answer your question


 
 
Foolios





PostPosted: Visual C# General, Drawing ellipses question Top

Yes, thank you.