473,396 Members | 2,034 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,396 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 4330
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.