获取标题栏高度,左右边框的宽度和下边框的高度
public class NonClientSize
{
public int TitleBar = 0;
public int LeftBorder = 0;
public int RightBorder = 0;
public int BottomBorder = 0;
}
protected NonClientSize GetNonClientSize()
{
NativeMethods.RECT rect = new NativeMethods.RECT();
rect.Left = rect.Right = rect.Top = rect.Bottom = 0;
var cp = CreateParams;//Form
SafeNativeMethods.AdjustWindowRectEx(ref rect, cp.Style, false, cp.ExStyle);
var nonClientSize = new NonClientSize();
nonClientSize.TitleBar = Math.Abs(rect.Top);
nonClientSize.LeftBorder = Math.Abs(rect.Left);
nonClientSize.RightBorder = rect.Right;
nonClientSize.BottomBorder = rect.Bottom;
return nonClientSize;
}
本文介绍了一种通过调整窗口矩形来计算非客户区尺寸的方法,包括标题栏高度、左右边框及底部边框的宽度。利用.NET Framework的P/Invoke调用Windows API函数AdjustWindowRectEx,实现获取这些尺寸。
1万+

被折叠的 条评论
为什么被折叠?



