Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

  • 7 months later...
  • Leaders
Posted

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).

[sIGPIC]e[/sIGPIC]
Posted

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.

Posted

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.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...