Window Size in Vista

ADO DOT NET

Centurion
Joined
Dec 20, 2006
Messages
160
Hi,
I set the Min Width and Height size of my window so user cannot resize it less than what I want!
I also set the size of window exactly the same as its Min Width and Height, so when program starts the my window is for example 400x300, and also cannot be resized less than 400x300.
It's OK in XP, but in Vista when I start my program it can be rsized a little less than what I set for window size and min win size!
Anyone faced this problem?! :confused:
 
There is something tricky about the way that Windows Forms designer does window sizes. Even though you specify a Size for the form, internally (in the InitializeComponent method) Visual Studio actually specifies the ClientSize (the size of the window minus the size of the borders).

The reason for this is that the border size of a window can vary with different border styles and can also be different on different computers (the larger Windows Xp title bar makes the border much thicker than the smaller "Classic Theme" title bar). Say you specify a 400x300 window and your controls fit perfectly within the window on your computer. If my computer displays with wider borders, your controls will no longer fit in the window; there will be less space for controls because the borders take up more space. By specifying ClientSize instead of Size, the Windows Forms designer ensures that there will always be the same amount of space for controls.

So, even though you specify a 400x300 form on your computer, it might end up being 404x314 on mine, which allows me to reduce the window size by 4x14 pixels and make the client area smaller than intended. This is probably the problem you are running into.

One workaround could be to check the border sizes and calculate the appropriate minimum size in the constructor. It might be possible to do this by simply setting the MinimumSize property to the Form's current Size after the ClientSize has been specified (in the constructor, or in the FormLoad event if you are using VB).
 
Why don't you get rid of the sizing grip...

In WPF: ResizeMode=NoResize
Winforms: BorderStyle= Fixed*

Has anyone else noticed this post is from Sep 2007. I think he's figured it out by now.
 
This is because OMID bumped the thread. Since back then the vista adoption rate has gone up and more of us are now on windows vista so we have a better grasp of whats going on. This made us think the post was more recent.

My 2cents, since I didn't notice the date until you mentioned it.
 
Back
Top