473,508 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GraphicsUnits - puzzle

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
Nov 16 '05 #1
3 5053
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
phil cunningham wrote:
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

Nov 16 '05 #2
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

"phil cunningham" <ph**@oakleafsoftwareNOSPAM.co.uk> wrote in
news:eN*************@TK2MSFTNGP10.phx.gbl...
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
Nov 16 '05 #3
As long as the printed reports are accurate I am happy with that.

Thanks for the very fast reply

Phil

"Niki Estner" <ni*********@cube.net> wrote in message
news:OX**************@TK2MSFTNGP11.phx.gbl...
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

"phil cunningham" <ph**@oakleafsoftwareNOSPAM.co.uk> wrote in
news:eN*************@TK2MSFTNGP10.phx.gbl...
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

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6081
by: Developwebsites | last post by:
Hi all, I've made a sliding puzzle game in shockwave which works just fine, except I dont know how to have it solve itself. the URL is: http://members.aol.com/rglukov/games/selfsolve.htm ...
1
13074
by: xavier vazquez | last post by:
I have a problem with a program that does not working properly...when the program run is suppose to generate a cross word puzzle , when the outcome show the letter of the words overlap one intop of...
0
2003
by: xavier vazquez | last post by:
have a problem with a program that does not working properly...when the program run is suppose to generate a cross word puzzle , when the outcome show the letter of the words overlap one intop of the...
5
4448
by: ashish0799 | last post by:
HI I M ASHISH I WANT ALGORYTHMUS OF THIS PROBLEM Jigsaw puzzles. You would have solved many in your childhood and many people still like it in their old ages also. Now what you have got to do...
3
3197
by: oncue01 | last post by:
Word Puzzle Task You are going to search M words in an N × N puzzle. The words may have been placed in one of the four directions as from (i) left to right (E), (ii) right to left (W), (iii) up...
6
2560
by: Phoe6 | last post by:
Hi All, I would like to request a code and design review of one of my program. n-puzzle.py http://sarovar.org/snippet/detail.php?type=snippet&id=83 Its a N-puzzle problem solver ( Wikipedia page...
2
2680
by: Gio | last post by:
I'm getting K&R (it's on the way), should I also get the Answer Book? And while I'm there, should I get the Puzzle Book? Or should I save the Puzzle Book for when I'm more advanced? - Gio ...
4
19761
by: honey777 | last post by:
Problem: 15 Puzzle This is a common puzzle with a 4x4 playing space with 15 tiles, numbered 1 through 15. One "spot" is always left blank. Here is an example of the puzzle: The goal is to...
5
4815
by: dmf1207 | last post by:
Hi All! I'm new to javascript and need a little help with a simple puzzle im trying to design. I have a 600x100 pixel picture that I have sliced into 6 100x100 rectangles making a table of of 6...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.