Strange issue with fixed form border styles in Vista

My previous post on this issue didn't have too many answers and it was peculiar and difficult to understand. I think I was able to understand the problem better and now I believe it is a Vista problem ...

The problem is with all types of fixed border styles like FixedDialog, Fixed3D, FixedSingle and FixedToolWindow. This doesn't happen on significant ones. This problem, as I said, also only happens on Vista.

Let's say you have a shape with any fixed border style and set the start location to 0.0. Here you want the form to be anchored to the top left corner of the screen. This works great if the style of the form's border is one of the relevant parameters, if it's corrected, well, the form will be slightly outside the working area of ​​the screen, both to the left and to the top.

What's weirder is that the location of the form does not change, and its threshold is 0.0, but a few pixels of the form still go off the stage.

I tested this on XP and it didn't happen, the problem is with Vista. In XP the only difference was the border size, which changed slightly between any styles. But the shape has always been perfectly aligned to the 0,0 position.

If possible, without , to determine how many pixels will be drawn off the artboard and then add that to the position of the form, is there a way to fix or cheat this?

0


a source to share


2 answers


If Aero is enabled, Windows will lie to you about the size and position of windows Fixed*

FormBorderStyle

. The following code shows how to get the correct height and top offset of such a window. A similar method will allow you to place the 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;
}

      

+1


a source


The reason I want to do this is to allow my application using a skin to enable or disable that skin. The whole app works fine with skin and I was trying to implement a property to enable and disable skin. The issue in this thread was one of the problems I have when the skin is disabled. Then I realized that I also have many other annoying skin disabling issues. This means that I will just forget about this feature for now and leave the skin always on. I just don't have time to deal with so many problems right now ...



Suggestion to close this question ...

0


a source