限制的形式来调整水平 [英] Limiting form resizing to horizontal

查看:103
本文介绍了限制的形式来调整水平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
垂直(只)可调大小的窗口在C#中形成

我有,我需要让用户只水平调整大小形状的情况。表格的最大宽度 X 。我该怎么做?

I have a case where I need to allow the user to resize the form just horizontally. The maximum width of the form is x. How can I do that?

推荐答案

设置MAXIMUMSIZE和的minimumSize到相同的高度,但可变的宽度。

Set your MaximumSize and MinimumSize to the same Height, but variable widths.

要使它所以调整大小光标不会出现在顶部或底部:

To make it so the resize cursor doesn't appear on the top or bottom:

protected override void WndProc(ref Message m) {
    base.WndProc(ref m);
    switch (m.Msg) {
        case 0x84: //WM_NCHITTEST
            var result = (HitTest)m.Result.ToInt32();
            if (result == HitTest.Top || result == HitTest.Bottom)
                m.Result = new IntPtr((int)HitTest.Caption);
            if (result == HitTest.TopLeft || result == HitTest.BottomLeft)
                m.Result = new IntPtr((int)HitTest.Left);
            if (result == HitTest.TopRight || result == HitTest.BottomRight)
                m.Result = new IntPtr((int)HitTest.Right);

            break;
    }
}
enum HitTest {
    Caption = 2,
    Transparent = -1,
    Nowhere = 0,
    Client = 1,
    Left = 10,
    Right = 11,
    Top = 12,
    TopLeft = 13,
    TopRight = 14,
    Bottom = 15,
    BottomLeft = 16,
    BottomRight = 17,
    Border = 18
}

代码复制,并从修改:垂直(只)大小可调Windows窗体在C#

Code copied and modified from: Vertically (only) resizable windows form in C#

这篇关于限制的形式来调整水平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆