积极答复者
如何将WPF长度单位与像素单位进行换算

问题
答案
-
你好,
可以使用下面的代码得到横向和纵向的换算率。
void MainWindow_Loaded(object sender, RoutedEventArgs e) { Matrix m = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice; double dx = m.M11; double dy = m.M22; }
Min Zhu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Bunliney 2011年11月10日 2:09
-
是的。这说明换算比是1:1。
我记得WPF的FontSize单位是pt,gdi+的是磅。单位是不一样的。你可以把FontSize换算下再试试。
为什么不直接用Textbox的大小呢?
Min Zhu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Bunliney 2011年11月10日 2:09
全部回复
-
你好,
可以使用下面的代码得到横向和纵向的换算率。
void MainWindow_Loaded(object sender, RoutedEventArgs e) { Matrix m = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice; double dx = m.M11; double dy = m.M22; }
Min Zhu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Bunliney 2011年11月10日 2:09
-
是的。这说明换算比是1:1。
我记得WPF的FontSize单位是pt,gdi+的是磅。单位是不一样的。你可以把FontSize换算下再试试。
为什么不直接用Textbox的大小呢?
Min Zhu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Bunliney 2011年11月10日 2:09