473,289 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

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.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
8 4314
Plater
7,872 Expert 4TB
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
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
7,872 Expert 4TB
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
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
7,872 Expert 4TB
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
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
7,872 Expert 4TB
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
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

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

Similar topics

0
by: mark | last post by:
Here's the most concise description I can give you of my problem... I'm trying to create a narrow form in Visual Basic.NET 2003. The form is about 95 pixels wide by 325 long. I resized it to...
1
by: John Tighe | last post by:
Changing the max or min size of a form can be in code, but if I do that then it causes build errors in my application. The build error is: Expression is a value and therefore cannot be the target...
6
by: Ayende Rahien | last post by:
Excetremely annoying problem, I've an application with a long startup time. So I created another form with my logo in it to as a splash screen. The splash screen is run from another thread and is...
5
by: VMI | last post by:
How can I increase the maximum size of a Windows form? I'm trying to make a really big Windows form (about 1000x1000) but the designer doesn't allow me to do that. It only goes up to 1000x780....
4
by: mark | last post by:
Here's the most concise description I can give you of my problem... I'm trying to create a narrow form in Visual Basic.NET 2003. The form is about 95 pixels wide by 325 long. I resized it to...
3
by: Chris Paul | last post by:
I'm having trouble with PHP & PostgreSQL/OpenLDAP/Apache on Windows. I've set this up countless times on BSD (piece of cake) but I'm trying to do this on Windows now so that my developer can work...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
8
by: BillE | last post by:
When I create a control dynamically and it grows according to the content, the control Height property still returns the original default control height instead of the height after expanding. ...
5
by: BillE | last post by:
I am using VB.NET, VS 2005 Add a windows form and in design view: Add a Radiobutton to the windows form Set AutoSize = True for the radiobutton Set the MaximumSize width to 90 for the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.