For some reason if you set both of the width and the height of Form.MaximumSize to zero it will let you have an unrestricted window size, however if you want to set a limit
Use INT_MAX since that's the theoretical limit that can be represented by a Size
anyway:
//Max width 200, unlimited height
this.MaximumSize = new Size(200, int.MaxValue);
Is it possible to set the Maximum Width for a Form but leave the Maximum Height Unrestricted?
Not really. You could simulate it as follows:
private void Form1_Resize(object sender, EventArgs e)
{
SetMaximumWidth();
}
private void Form1_Load(object sender, EventArgs e)
{
SetMaximumWidth();
}
private void SetMaximumWidth()
{
if (Width > 200)
Width = 200;
}
I know the question is a couple of years old but I met the same problem and what I did was to set one of the parameter to the resolution of the screen, assuming the size of the form cannot exceed the size of the screen.
this.MaximumSize = new Size(200, Screen.PrimaryScreen.Bounds.Height);
Hopes this helps someone.