How to resize the width but not the height in run time

danyeungw

Well-known member
Joined
Aug 30, 2005
Messages
73
Programming Experience
10+
I created a form in VB.NET 2.0. The width was 477 and height was 255. I wanted the form can be resized at run time for the width but not the height. So I add 255 in Maximum Size for the height and left the width with 0. As soon as I added 255 to the height maximum size, the form width changed to 123 automatically in design. I tried to enter 477 width in Size property but it didn't let me. Why? What did I do wrong?

Thanks.
DanYeung
 
try this for disable resizable form :
VB.NET:
 Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog

Several Fixed 'mode' to choose :

Member name Description
CFW.gif
Fixed3D A fixed, three-dimensional border.
CFW.gif
FixedDialog A thick, fixed dialog-style border.
CFW.gif
FixedSingle A fixed, single-line border.
CFW.gif
FixedToolWindow A tool window border that is not resizable. A tool window does not appear in the taskbar or in the window that appears when the user presses ALT+TAB. Although forms that specify FixedToolWindow typically are not shown in the taskbar, you must also ensure that the ShowInTaskbar property is set to false, since its default value is true.
CFW.gif
None No border.
CFW.gif
Sizable A resizable border.
CFW.gif
SizableToolWindow A resizable tool window border. A tool window does not appear in the taskbar or in the window that appears when the user presses ALT+TAB.
 
Let's see. I've got a MinimumSize property and a MaximumSize property. I want the form to be able to be resized widthwise but not heightwise. I know! Whay don't I set the Height component of the MinimumSize and MaximumSize to the same value, which will keep the Height of the form at that specific value. Then I'll set the Width component of the MinimumSize to zero and the Width component of the MaximumSize to the largest value it will allow. Then I'll set the Size property to my desired initial size. Now I've got a form that is the size I want and can change its width but not its height. Dare I say, that's more common sense than programming.
 
Back
Top