我如何计算在WPF非客户端窗口的大小? [英] How do I compute the non-client window size in WPF?

查看:185
本文介绍了我如何计算在WPF非客户端窗口的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WPF有<一个href="http://msdn.microsoft.com/en-us/library/system.windows.systemparameters.aspx"><$c$c>SystemParameters类暴露系统指标的大量。在我的电脑我已经注意到,一个普通的窗口有一个标题是30像素高,边框是8个像素宽。这是Windows 7的Aero主题启用:

WPF has the SystemParameters class that exposes a great number of system metrics. On my computer I have noticed that a normal window has a title that is 30 pixels high and a border that is 8 pixels wide. This is on Windows 7 with the Aero theme enabled:

不过, SystemParameters 返回以下值:

SystemParameters.BorderWidth = 5
SystemParameters.CaptionHeight = 21

在这里,我已禁用Aero主题:

Here I have disabled the Aero theme:

现在, SystemParameters 返回以下值:

SystemParameters.BorderWidth = 1
SystemParameters.CaptionHeight = 18

我如何使用计算实际观测值 SystemParameters

推荐答案

有关您需要使用不同的参数来计算的大小可调整大小的窗口:

For a resizable window you need to use a different set of parameters to compute the size:

var titleHeight = SystemParameters.WindowCaptionHeight
  + SystemParameters.ResizeFrameHorizontalBorderHeight;
var verticalBorderWidth = SystemParameters.ResizeFrameVerticalBorderWidth;

这些大小将在修改的主题变化。

These sizes will change when you modify the theme.

这篇关于我如何计算在WPF非客户端窗口的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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