Windows.Forms form ignoring MaximumSize and Size attributes, but only on startup

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sheridan
    New Member
    • Oct 2007
    • 9

    Windows.Forms form ignoring MaximumSize and Size attributes, but only on startup

    Hi.

    I'm hoping someone can shed some light on this bizarre problem that I have come accross. I have spent all evening trying to fix it with no luck!

    I have a frameless Windows.Forms form with a transparent background displaying a .png image with rounded corners. The form holds a WebBrowser instance and can be open or closed. When closed, a thin bar .png is used for the background. So far, so good.

    Here's the problem:
    When the form is first launched, it is in it's closed state:


    this.ClientSize = new System.Drawing. Size(371, 29);
    this.MaximumSiz e = this.Size = new System.Drawing. Size(371, 29);

    However, despite these lines of code, the form always starts with a minimum height of about 35 - 40 px, which shows the top 10px or so of the WebBrowser (white rectangle in picture). Adjusting the values in the lines of code above below this level make NO difference whatsoever, but making them 40px or more DOES make the form size change.

    Now here's the really strange bit:
    When I click the open button to show the WebBrowser and then click it again to close it to the 29px height control bar, it DOES go to 29px. (see picture below)



    I have tried calling the button's Click method programmaticall y in the constructor and that doesn't work either. I've tried everything that I can think of, so I'm really hoping someone can help me out here.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Have you set this.Size to anything? What are settings defaulted to in the designer?
    And what is the WindowState at startup, sometimes they do funny things

    Comment

    • sheridan
      New Member
      • Oct 2007
      • 9

      #3
      this.Size is set as shown in my post in the InitializeCompo nent() method and again in the button Click method as shown below:

      private void OpenCloseButton _MouseDown(obje ct sender, MouseEventArgs e)
      {
      if (this.Size.Heig ht > 50) CloseResultsBox ();
      else OpenResultsBox( );
      }

      private void OpenResultsBox( )
      {
      if (this.Size.Heig ht < 50)
      {
      ...
      this.Size = this.MaximumSiz e = new System.Drawing. Size(371, 524);
      ...
      }
      }

      Note that I have to check if this.Size.Heigh t < 50 because it doesn't initially get set to it's correct height of 29.
      Both MaximumSize and Size are set to 379, 29 in the designer just as they are in the Designer.cs file? The WindowState is Normal throughout use of the application.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Hmm. In the designer your form doesn't have a border and you turn it off at runtime does it? I have seen my forms change sizes when changing the FormBorderStyle proeprty.

        And your first post only showed this.ClientSize , not this.Size (if there is a difference?)

        Comment

        • sheridan
          New Member
          • Oct 2007
          • 9

          #5
          Nope. I have set the FormBorderStyle to None in the Designer, not programatically . All I do programatically is change this.Size, this.MaximumSiz e and this.Background between the full size and the reduced size shown in the pics in the first post.
          Below is a screengrab of the Form properties:


          And my first post does show this.Size.. on the this.MaximumSiz e line. I'm not sure what the difference is with ClientSize, but the Designer always seems to add it. I think it is the actual area available, not including any parent's border and padding, scrollbars, etc., but I'm not sure really.

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Oh ok I see it yeah, you set it with the maxsize, i'm not familiar with the tripling up of commands like that so I missed it.

            Is MaximumSize needed in your context? Do you provide a way for users to resize your form? I would think it would just switch between "Maximized"(whi ch ignores MaximumSize right?) and the normal size (your .Size / .ClientSize)
            Have you tried leaving out all references to MaxmimumSize (just for testing if need be) to see if that effects it at all? It would be a longshot, but itterate through all posibilities?

            Comment

            • sheridan
              New Member
              • Oct 2007
              • 9

              #7
              Yeah, I wondered about the need for MaximumSize myself, but it made no difference without it. This is just the wierdest thing.

              I think it might be something to do with the height of the top of the frame (where the icon and close button normally go), despite it being set to None and invisible in my application. I had a similar problem with a small clock app, where there was an extra grey space under the thin gui. I got rid of it by changing a component's background to the colour set on the transparency key, but unfortunately that isn't applicable here. The initial (incorrect) height of this Dictionary app is round about the same size as the top of the frame usually is when present.

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Hmm, when do you re-declare the size constraints? If at all?
                Like if you set the size in the _Load() or _Shown() events to see if it fixes it?

                Comment

                • sheridan
                  New Member
                  • Oct 2007
                  • 9

                  #9
                  The only time I declare this.Size has been shown above. On your suggestion though, I added a Load method and put a size declaration in there and it sorts the problem right out! So now it appears correctly from the start.

                  Many many thanks for your help and patience. :)

                  Comment

                  Working...