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