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

前端 未结 3 606
别跟我提以往
别跟我提以往 2021-01-11 18:28

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

3条回答
  •  长情又很酷
    2021-01-11 19:12

    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;
        }
    

提交回复
热议问题