Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
In windows applications form height should be flexible but width should be fixed. so which property should i use. For fixed width i used FORM border style is fixed size and maximize box is false.
Posted

You can achieve this easily by setting the Form's 'MinimumSize and 'MaximumSize properties in the Property Browser, or in code:

1. set the Width component of both 'MinimumSize and 'MaximumSize to the same value.

2. set the Height component of 'MinimumSize to the minimum Form height you wish to allow.

3. set the Height component of 'MaximumSize to the maximum Form height you wish to allow.
 
Share this answer
 
Comments
chintu fron cali 26-Feb-14 18:01pm    
Thank you very much your answer helped
I would suggest overriding the OnResize() method, placing the logic in there.

C#
public class YourForm : Form
{
   private const int FixedWidth = 1024;

   protected override void OnResize(EventArgs e) {
      if (this.Width != FixedWidth) {
         return;
      }
      base.OnResize(e);
   }
}


This may have to be adapted to your real needs/logic.

Hope this helps.
 
Share this answer
 
Comments
BillWoodruff 26-Feb-14 12:17pm    
This will not affect the Form's re-sizing. Even if you reset the Width of the Form in the over-ridden OnResize method, at run-time the user will still be able to drag and change the visible size: when a mouse-up terminates the drag, then the Form will "snap" to the fixed size, which would be confusing to the end-user. See my response below for a simple way to handle keeping a Form at a fixed width.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900