-1

I was looking on the internet but I didn't find an answer. I need to know in what kind of units drawEllipse works: pixels, centimetres...

I also need to know if there is a easy way to change that units (I need it on centimetres).

Thanks a lot!

Imrik
  • 674
  • 2
  • 14
  • 32
  • Let's say we have Winforms here. Then lets look what documentation states about [Form.Size](https://msdn.microsoft.com/en-us/library/25w4thew(v=vs.110).aspx)... – Renatas M. Mar 07 '17 at 11:03

2 Answers2

1

Well, you didn't look too carefully.

DrawEllipse is a method of the System.Drawing.Graphics class. Graphics implements the PageUnit property which:

Gets or sets the unit of measure used for page coordinates in this Graphics.

The possible values are given by the GraphicsUnit enumeration.

InBetween
  • 32,319
  • 3
  • 50
  • 90
1

The default value is measured in Pixel. You can check it by printing this information onto your Form using the PageUnit property like this:

protected override void OnPaint(PaintEventArgs e)
{
    e.Graphics.DrawString(e.Graphics.PageUnit.ToString(), new Font("Arial", 14), Brushes.Black, 50, 50);
}

This property can also be used to set the desired unit of measurement like this:

protected override void OnPaint(PaintEventArgs e)
{
    e.Graphics.PageUnit = GraphicsUnit.Millimeter;
    e.Graphics.DrawEllipse(new Pen(Color.Black), 100, 100, 25, 30);
}

Now you should have a black ellipse with a width of 2.5 cm and a height of 3.0 cm at the coordinates of 10 cm in X and 10 cm in Y dimension

Mong Zhu
  • 23,309
  • 10
  • 44
  • 76