views:

49

answers:

3

I have a panel. I need to represent it in WYSIWYG.

Now, when drawing on it, is possible to draw using millimeters instead of pixels.

graphics.PageUnit = GraphicsUnit.Millimeter
graphics.DrawRectangle(pen,rect)

Is it possible to position the controls(buttons, textboxes) also in millimeters, in order to get a "real" paper image of the panel?

In VB6 this was possible. Is .NET a step backward or VB6 just use the approximation that we don't want to use in .NET?

A: 

Try this:

var dpiX = Graphics.DpiX;//horizontal
var dpiY = Graphics.DpiY;//vertical

var mmX = (width_in_pixles * 25.4 ) / dpiX;
var mmY = (height_in_pixles * 25.4) / dpiY;

There are 25.4 mm in 1 inch so using the above formulas you can calculate heights and widths of controls in mm and adjust their positions also.

TheVillageIdiot
DPI should mean **DOTS** per inch, not **Pixels** per inch.
serhio
+1  A: 

Quite simply, I don't believe this is possible, without performing specific math for each monitor you support.

DPI is commonly used for printing, and is useful for measurements on paper. However, measurements on a monitor are not guaranteed, since you can change resolutions at any time and still have the same DPI (typically 96). Beyond that you need to also consider monitor size.

What you need to know is the Pixel Density, or PPI, for your specific monitor. I don't believe this can be obtained, although others can correct me if I'm wrong.

Will Eddins
hm. So what, VB6 is more powerful that VB.NET?
serhio
Should the measurements be accurate in terms of printing size or screen size? I'm not sure how VB6 works exactly, but from what I'm seeing on Google, VB6's measurements are only accurate for printing.
Will Eddins