By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,988 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,988 IT Pros & Developers. It's quick & easy.

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

P: 9
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.MaximumSize = 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 programmatically 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.
Feb 1 '09 #1
Share this Question
Share on Google+
8 Replies


Plater
Expert 5K+
P: 7,872
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
Feb 2 '09 #2

P: 9
this.Size is set as shown in my post in the InitializeComponent() method and again in the button Click method as shown below:

private void OpenCloseButton_MouseDown(object sender, MouseEventArgs e)
{
if (this.Size.Height > 50) CloseResultsBox();
else OpenResultsBox();
}

private void OpenResultsBox()
{
if (this.Size.Height < 50)
{
...
this.Size = this.MaximumSize = new System.Drawing.Size(371, 524);
...
}
}

Note that I have to check if this.Size.Height < 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.
Feb 2 '09 #3

Plater
Expert 5K+
P: 7,872
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?)
Feb 2 '09 #4

P: 9
Nope. I have set the FormBorderStyle to None in the Designer, not programatically. All I do programatically is change this.Size, this.MaximumSize 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.MaximumSize 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.
Feb 2 '09 #5

Plater
Expert 5K+
P: 7,872
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"(which 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?
Feb 2 '09 #6

P: 9
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.
Feb 2 '09 #7

Plater
Expert 5K+
P: 7,872
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?
Feb 2 '09 #8

P: 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. :)
Feb 2 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.