50% OFF!!!

Sunday, May 22, 2011

c# WinForm | Check form window size and location


I wanted to open a new window form, exactly near another form. (pinning one form to another).
Because of the border difference among Windows XP, Vista and Windows7 (win7), it didn't work easily.

So to determine windows size under win7/vista, I had to check if Windows Aero. (checking made by short&easy code)

Now, after checking this, I had to also support winXP (which does not have AERO technology).

For finding the left and right window border size (width) I used the SystemInformation Class which provides information about the current system environment.

I recommend to check if it works for other FormBorderStyle.

The code:
internal static bool IsAeroEnabled()
    bool isEnabled = false;
    if (Environment.OSVersion.Version.Major >= 6)
            DwmIsCompositionEnabled(out isEnabled);
        catch (Exception ex)
    return isEnabled;
internal static extern int DwmIsCompositionEnabled(out bool enabled);

Best regard,
MDB Blog

No comments:

Post a Comment