是否有可能获得布局的物理尺寸? [英] Is it possible to obtain physical dimensions of layouts?

查看:87
本文介绍了是否有可能获得布局的物理尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以以毫米,英寸为单位获得布局尺寸?



Hong

Is it possible to obtain dimensions of layouts in units such as mm, inch?


Hong

推荐答案

Hi Hong,

Hi Hong,

根据您的描述,我建议您使用等式:
物理尺寸=像素尺寸/分辨率。

According to your description, I’d like to suggest you to use equation: physical dimensions = pixel size/resolution.

获取屏幕分辨率

Get the Screen Resolution

我们需要得到窗口的句柄你可以从:
System.Windows.Browser.HtmlPage.Window;

现在来自该对象,您可以使用适当的参数"screen.width"调用Eval()。或者"screen.height"或"screen.height"。分别获得屏幕宽度或屏幕高度。这些将为您提供屏幕分辨率。假设您收到Width = 1024且Height = 768,则表示
您的屏幕分辨率为:1024 x 768。

Now from that object, you can call the Eval() with proper parameter "screen.width" or "screen.height" to get the Screen Width or Screen Height respectively. Those will give you the Screen Resolution. Suppose, you received Width = 1024 and Height = 768, means your Screen Resolution is: 1024 x 768.

示例代码:

var 宽度=
HtmlPage .Window.Eval( " screen.width" );

var 高度=
HtmlPage .Window.Eval( " screen.height" ; );

获取像素大小

我们可以通过调用Measure方法让控件自行测量(没有显示)。当然,它可能没有无限宽度和高度,所以根据你的用例,你可能更愿意让你的根元素测量自己,
将反过来衡量所有孩子。

We can ask the control to measure itself (without it yet being displayed) by calling its Measure method. Of course, it may not have infinite width and height, so depending on your use case you may prefer to ask your root element to measure itself, which will in turn measure all children.

示例代码:

LayoutRoot.Measure( new 大小 。PositiveInfinity,
double 。PositiveInfinity));

LayoutRoot.Measure(newSize(double.PositiveInfinity, double.PositiveInfinity));

var width1 = LayoutRoot.DesiredSize。宽度;

varwidth1 = LayoutRoot.DesiredSize.Width;

var height1 = LayoutRoot.DesiredSize。高度;

varheight1 = LayoutRoot.DesiredSize.Height;

最后,我们可以获得物理维度。

At last, we can get the physical dimension.

示例代码:            

Sample code:           

double wid = width1 / 转换 。ToDouble(Width);

double hei = height1 / 转换 。ToDouble(
Height);

MessageBox 。显示( string 。格式( "当前
尺寸:{0}英寸  X {1}英寸"
,wid,hei));

MessageBox.Show(string.Format("Current size : {0}inch  X {1}inch", wid, hei));

如果我误解你,请告诉我。

Please let me know if I have misunderstood you.


这篇关于是否有可能获得布局的物理尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆