开发者

Snap to grid in millimeters on a panel?

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 appro开发者_JAVA技巧ximation that we don't want to use in .NET?


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.


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.


Till this, an acceptable solution:

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/ffb7e52d-8533-465c-bd57-17f7b704c927

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜