GraphicsUnits - puzzle

  • Thread starter phil cunningham
  • Start date
P

phil cunningham

I am just starting with C# Graphics programming and need some help with this.

As I understand it, setting "..PageUnit=GraphicsUnits.Millimeter" means that the drawing units are taken to be mm.
However, in the following code the rectangle is displayed with dimensions 120mm square (as measured with a rular on the screen!)

protected override void OnPaint(PaintEventArgs e)
{
Graphics g=e.Graphics;
g.PageUnit = GraphicsUnit.Millimeter;
Rectangle bb= new Rectangle(0,0,100,100);
g.DrawRectangle(new Pen(Color.Red,1/g.DpiX ),bb);
}

If I change the code to draw a box 3.937" (equivalent to 100mm) and set the GraphicUnits to Inch - I also get a box about 120mm square.

protected override void OnPaint(PaintEventArgs e)
{
Graphics g=e.Graphics;
g.PageUnit = GraphicsUnit.Inch;
RectangleF bb= new RectangleF(0,0,3.937008f,3.937008f);
g.DrawRectangle(new Pen(Color.Red,1/g.DpiX ),Rectangle.Round(bb));
}

It seems as if the real measurements on screen are different to what I expect - am I missing something here.

This is important as I need to show real word objects at their correct size on screen and printed reports.

Any help anyone can offer will be much appreciated


Phil Cunningham
 
R

Ryan Gregg

Sounds like the resolution that Windows believes your monitor is and the
resolution is actually is are different. However, I'm not sure how you
would go about properly configuring Windows, and my guess would be that
most people's computers are not properly configured for this.

Ryan
 
N

Niki Estner

You can adjust your monitor's DPI-setting under Control Panel - Display
Properties - Settings Tab - Advanced. AFAIK this value is used for pixel-mm
conversion. However you should assume that many people got that setting
wrong, and that few of them will want to change it for your application (it
also changes dialog font sizes, control sizes, etc). You should probably use
your own calibration factor for screen display.
However the GDI value should be correct for printers and metafiles.

Niki

I am just starting with C# Graphics programming and need some help with
this.

As I understand it, setting "..PageUnit=GraphicsUnits.Millimeter" means that
the drawing units are taken to be mm.
However, in the following code the rectangle is displayed with dimensions
120mm square (as measured with a rular on the screen!)

protected override void OnPaint(PaintEventArgs e)
{
Graphics g=e.Graphics;
g.PageUnit = GraphicsUnit.Millimeter;
Rectangle bb= new Rectangle(0,0,100,100);
g.DrawRectangle(new Pen(Color.Red,1/g.DpiX ),bb);
}

If I change the code to draw a box 3.937" (equivalent to 100mm) and set the
GraphicUnits to Inch - I also get a box about 120mm square.

protected override void OnPaint(PaintEventArgs e)
{
Graphics g=e.Graphics;
g.PageUnit = GraphicsUnit.Inch;
RectangleF bb= new RectangleF(0,0,3.937008f,3.937008f);
g.DrawRectangle(new Pen(Color.Red,1/g.DpiX ),Rectangle.Round(bb));
}

It seems as if the real measurements on screen are different to what I
expect - am I missing something here.

This is important as I need to show real word objects at their correct size
on screen and printed reports.

Any help anyone can offer will be much appreciated


Phil Cunningham
 
P

phil cunningham

As long as the printed reports are accurate I am happy with that.

Thanks for the very fast reply

Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top