Vista 中固定表单边框样式的奇怪问题

发布于 2024-07-19 03:17:46 字数 561 浏览 4 评论 0原文

我之前关于这个问题的文章没有得到太多答案,而且有点具体且难以理解。 我想我已经更好地理解了这个问题,现在我相信这是一个 Vista 问题...

问题在于所有类型的固定边框样式,如 FixDialog、Fixed3D、FixedSingle 和 FixToolWindow。 它不会发生在体型较大的人身上。 这个问题,就像我说的,也只发生在 Vista 上。

假设您有一个具有任何固定边框样式的表单,并将起始位置设置为 0,0。 您想要的是将表单捕捉到屏幕的左上角。 如果表单边框样式是相当大的选项之一,则效果很好,如果它是固定的,那么表单将在屏幕工作区域的左侧和顶部之外一点。

更奇怪的是,表单位置没有改变,仍然是 0,0,但是表单的几个像素仍然绘制在工作屏幕区域之外。

我在 XP 上测试了这个问题,但没有发生,问题是 Vista 特有的。 在 XP 上,唯一的区别是边框大小在任何样式之间略有变化。 但窗体总是完美地捕捉到位置 0,0。

如果可能,无需查找在工作区域之外绘制了多少像素,然后将其添加到表单位置,是否有可能的方法来修复或解决此问题?

My previous post about this issue didn't got too many answers and it was kinda specific and hard to understand. I think I've managed to understand the problem better and I now believe it to be a Vista issue...

The problem lies on all types of fixed border styles like FixedDialog, Fixed3D, FixedSingle and FixedToolWindow. It does not happen on the sizable ones. This problem, like I said, it also happens only on Vista.

Let's say you have a form with any of the fixed border styles and set the starting location to 0,0. What you want here is for the form to be snapped to the top left corner of the screen. This works just fine if the form border style is one of the sizable options, if it's fixed, well, the form will be a little bit outside of the screen working area both to the left and top.

What's more strange about this is that the form location does not change, it sill is 0,0, but a few pixels of the form are still drawn outside of the working screen area.

I tested this on XP and it didn't happen, the problem is Vista specific. On XP, the only difference was the border size that change a bit between any of the styles. But the form was always perfectly snapped to position 0,0.

If possible, without finding how many pixels are being drawn outside of the working area and then add that to the form location, is there a possible way to fix or workaround this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野侃 2024-07-26 03:17:46

如果启用 Aero,Windows 会欺骗您有关 Fixed* FormBorderStyle 窗口的大小和位置。 以下代码显示如何获取此类窗口的正确高度和顶部偏移量。 类似的技术将允许您将窗口放置在 (0,0) 处。

[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;
    try
    {
        // 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;
            }
        }
    }
    catch
    {
    }
    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 MyWindowY()
{
    int y = Location.Y;
    if (AeroIsMessingWithUs())
    {
        // I'm actually 5 pixels higher than Windows says I am
        y -= 5;
    }
    return y;
}

If Aero is enabled, Windows will lie to you about the size and position of Fixed* FormBorderStyle windows. The following code shows how to get the correct height and top-offset of such a Window. A similar technique will allow you to place a window at (0,0).

[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;
    try
    {
        // 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;
            }
        }
    }
    catch
    {
    }
    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 MyWindowY()
{
    int y = Location.Y;
    if (AeroIsMessingWithUs())
    {
        // I'm actually 5 pixels higher than Windows says I am
        y -= 5;
    }
    return y;
}
星光不落少年眉 2024-07-26 03:17:46

我想这样做的原因是允许我的应用程序(应用了皮肤)启用或禁用该皮肤。 整个应用程序与皮肤配合良好,我试图实现一个属性来启用和禁用皮肤。 这个主题的问题是我在禁用皮肤时遇到的问题之一。 然后我意识到,如果皮肤被禁用,我还有很多其他恼人的问题需要处理。 这意味着我现在会忘记这个功能并暂时让皮肤始终处于打开状态。 我现在只是没有时间处理这么多问题...

建议结束这个问题...

The reason I want to do this is to allow my application, which has a skin applied, to enable or disable that skin. The whole application is working fine with the skin and I was trying to implement a property to enable and disable the skin. The issue on this topic was one of the problems I'm having when the skin is disabled. I then realized that I also have a lot of other annoying problems to deal with if the skin is disabled. Which means I'll just forget about this feature for now and leave the skin always on in the time being. I just don't have the time to handle so many issues right now...

Proposing to close this question...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文