Vertically (only) resizable windows form in C#

前端 未结 6 1529
时光取名叫无心
时光取名叫无心 2020-12-04 14:55

I have a situation where it would be beneficial to me to allow my windows form to be resized by the user, but only vertically. After some searching, it seems like there isn\

6条回答
  •  佛祖请我去吃肉
    2020-12-04 15:12

    To avoid the "rubber-banding" effect of @orsogufo's solution:

    public Form1()
    {
        InitializeComponent();
        this.MinimumSize = new Size(500, 0);
        this.MaximumSize = new Size(500, Screen.AllScreens.Max(s => s.Bounds.Height));
    }
    

    It won't correctly adjust its maximum height to accommodate a larger screen if you resize the screen bounds, but for static screen sizes it works great.

提交回复
热议问题