Winforms 是否获取包含非客户端区域的windows窗体的总高度?

Winforms 是否获取包含非客户端区域的windows窗体的总高度?,winforms,Winforms,如何获取包含非客户端区域的windows窗体的总高度?大小似乎不适用于我的窗口(FormBorderStyle=FixedToolWindow,如果有帮助的话)。尝试窗体的DesktopBounds属性。尝试窗体的DesktopBounds属性。大小属性肯定会起作用。请注意,由于设计机器和生产机器之间的系统字体或视频适配器DPI设置不同,表单可能会被重新缩放。在加载事件之前,实际大小将不可用。size属性肯定会起作用。请注意,由于设计机器和生产机器之间的系统字体或视频适配器DPI设置不同,表单可

如何获取包含非客户端区域的windows窗体的总高度?大小似乎不适用于我的窗口(FormBorderStyle=FixedToolWindow,如果有帮助的话)。

尝试窗体的DesktopBounds属性。

尝试窗体的DesktopBounds属性。

大小属性肯定会起作用。请注意,由于设计机器和生产机器之间的系统字体或视频适配器DPI设置不同,表单可能会被重新缩放。在加载事件之前,实际大小将不可用。

size属性肯定会起作用。请注意,由于设计机器和生产机器之间的系统字体或视频适配器DPI设置不同,表单可能会被重新缩放。在加载事件之前,实际大小将不可用。

如果启用Aero并且您的
FormBorderStyle
FixedToolWindow
,则窗口将显示窗体的大小。我认为以下
格式的代码将给出此类窗口的正确高度和宽度

[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern bool DwmIsCompositionEnabled();

// When Aero is enabled, and our FormBorderStyle is FixedToolWindow,
//    Windows will lie to us about our size and position.
public bool AeroIsMessingWithUs()
{
    bool ret = false;

    // check for other Fixed styles here if needed
    if (FormBorderStyle == System.Windows.Forms.FormBorderStyle.FixedToolWindow)
    {
        if (Environment.OSVersion.Version.Major >= 6 && DwmIsCompositionEnabled())
        {
            // Aero is enabled
            ret = true;
        }
    }
    return ret;
}

public int MyWindowHeight()
{
    int height = Height;
    if (AeroIsMessingWithUs())
    {
        // there are actually 5 more pixels on the top and bottom
        height += 10;
    }
    return height;
}

public int MyWindowWidth()
{
    int width = Width;
    if (AeroIsMessingWithUs())
    {
        // there are 5 more pixels on the left and right
        width += 10;
    }
    return width;
}

如果启用Aero,并且
FormBorderStyle
FixedToolWindow
,则窗口将与窗体大小有关。我认为以下
格式的代码将给出此类窗口的正确高度和宽度

[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern bool DwmIsCompositionEnabled();

// When Aero is enabled, and our FormBorderStyle is FixedToolWindow,
//    Windows will lie to us about our size and position.
public bool AeroIsMessingWithUs()
{
    bool ret = false;

    // check for other Fixed styles here if needed
    if (FormBorderStyle == System.Windows.Forms.FormBorderStyle.FixedToolWindow)
    {
        if (Environment.OSVersion.Version.Major >= 6 && DwmIsCompositionEnabled())
        {
            // Aero is enabled
            ret = true;
        }
    }
    return ret;
}

public int MyWindowHeight()
{
    int height = Height;
    if (AeroIsMessingWithUs())
    {
        // there are actually 5 more pixels on the top and bottom
        height += 10;
    }
    return height;
}

public int MyWindowWidth()
{
    int width = Width;
    if (AeroIsMessingWithUs())
    {
        // there are 5 more pixels on the left and right
        width += 10;
    }
    return width;
}

如果
FormBorderStyle
FixedToolWindow
,那么我认为
DesktopBounds
给出的答案并不比
Size
更好。如果启用Aero,我认为这两个选项都不正确。如果
FormBorderStyle
FixedToolWindow
,那么我认为
DesktopBounds
给出的答案不会比
Size
更好。我认为如果启用Aero,这两种方法都是不正确的。