Windows 7 - Reported Form size is wrong

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    Windows 7 - Reported Form size is wrong

    I'm running Window7 64bit, RTM.
    To give this application the ability to switch between a moveable frame and no frame I am using the following methods
    Code:
    		void Fixed()
    		{
    			Point pBefore = this.Location;
    			Size sBefore = this.Size;
    			FormBorderStyle = FormBorderStyle.None;
    			this.BackColor = Color.FromKnownColor(KnownColor.Black);
    			this.Location = pBefore;
    			this.Size = sBefore;
    		}
    		void Moveable()
    		{
    			Point pBefore = this.Location;
    			Size sBefore = this.Size;
    			FormBorderStyle = FormBorderStyle.Sizable;
    			this.BackColor = Color.FromKnownColor(KnownColor.Control);
    			this.Location = pBefore;
    			this.Size = sBefore;
    		}
    One would expect that the size and location to remain constant, but they don't.
    If I make the form Moveable(), then click maximize the form should now be 1920x1200 (Dell 24" widescreen)

    But when I then make the form Fixed(), this.size() returns as 1936x1216. The reported size has grown by 16 pixel on each axis. Furthermore the location has shifted from 0,0 to -8,-8 which would be half of that 16 pixel difference.

    My thinking is that since Windows7 has fancy effects like a feathered drop shadow all around the form, that the form technically extends to the edge of the drop shadow. Then when you click Maximize Windows7 is cheating and making it 16 pixels too big and offsetting by 8.

    Does anyone have any better guess? Or know a way to check if there is a drop shadow visual effect so I take that into account in my size calculations?
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Update:
    SystemInformati on has a couple new (at least to me) properties.
    PrimaryMonitorM aximizedWindowS ize = 1936x1216
    PrimaryMonitorW indowSize = 1920x1200

    That would be good if I could count on always being on the Primary Monitor, but that's not right. I guess the Maximized dimension less the Windows size, divided by two shows the drop shadow width

    Or I could trust FrameBorderSize = 8, 8

    I guess I just have to handle the third condition not just of resized but of maximized. I love complications.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      The size of your form reported in .Size changes depending on the form border style. Does that effect you?

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Of course. But since they are forms that I'm creating I have some control over that. I'm switching between .None and .Sizeable.

        I filter the "before" sizes depending on whether or not the form went maximized
        Code:
        if (WindowState == FormWindowState.Maximized)
        {
            pBefore = new Point(this.Location.X + SystemInformation.FrameBorderSize.Width, this.Location.Y + SystemInformation.FrameBorderSize.Height);
            sBefore = new Size(this.Size.Width - SystemInformation.FrameBorderSize.Width * 2, this.Size.Height - SystemInformation.FrameBorderSize.Height * 2);
        }
        else
        {
            pBefore = this.Location;
            sBefore = this.Size;
        }

        Then when resizing some of the interior components I take into account the boarder dynamically
        Code:
        SystemInformation.CaptionHeight * (FormBorderStyle == FormBorderStyle.None ? 0:1) -
        SystemInformation.FrameBorderSize.Height * (FormBorderStyle == FormBorderStyle.None ? 0:1);
        If the border style is none then ? returns 0, meaning border width times zero is still zero. If there is a border we take that times 1 for the bottom and the caption height times 1 for the top.

        Comment

        Working...