Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set the Maximum Width for a Form but leave the Maximum Height Unrestricted?

Tags:

c#

winforms

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 you have to do it for both width and height at the same time. I want a fixed width but no limit on height.

    // No Limits
    this.MaximumSize = new Size(0,0);

    // Form Height will be stuck at 0
    int ArbitraryWidth = 200;
    this.MaximumSize = new Size(ArbitraryWidth, 0);
like image 574
Paul Matthews Avatar asked Nov 23 '12 10:11

Paul Matthews


People also ask

Is it possible to resize a control within the form design window if yes how?

Resize with the designerBy dragging either the right edge, bottom edge, or the corner, you can resize the form. The second way you can resize the form while the designer is open, is through the properties pane. Select the form, then find the Properties pane in Visual Studio. Scroll down to size and expand it.

How do I fix the size of a form in C#?

Right click on your form and go to properties. Then go to Layout options,see there are a property named Size. Change it as your need as width and length wise. Also see a property named StartPosition just after the Size property.

Is used to set the position of form at run time view?

Remarks. This property enables you to set the starting position of the form when it is displayed at run time. The form's position can be specified manually by setting the Location property or use the default location specified by Windows.


1 Answers

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);
like image 100
Dan Bechard Avatar answered Dec 04 '22 07:12

Dan Bechard