Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Winforms - resize a window, but only allow change of height

Tags:

winforms

Using Winforms, is there a way to allow resize, but only to allow the window to be made taller? The ability to make it wider not only wouldn't be allow, but would also be pleasing to the user.

Additionally, the ability to set a minimum height, and also be pleasing to the user?

like image 475
pearcewg Avatar asked Jan 22 '23 17:01

pearcewg


1 Answers

You can set the Form.MinimumSize and Form.MaximumSize properties in say the Forrm Load event:

this.MinimumSize = new Size(400, 0);
this.MaximumSize = new Size(400, Screen.PrimaryScreen.Bounds.Height);

Or you could simply handle the Form resize event:

private void Form1_Resize(object sender, EventArgs e)
{
    this.Width = 400; 
}

The first option is probably better as it avoids the flickering on resizing.

like image 64
Ash Avatar answered Jan 29 '23 13:01

Ash