垂直(只)可调大小的窗口在C#中形成 [英] Vertically (only) resizable windows form in C#

查看:270
本文介绍了垂直(只)可调大小的窗口在C#中形成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,那将是对我有益的,让我的窗户形式,由用户调整,但只会垂直。经过一番搜索,似乎没有太多关于这个特定主题。这可能吗?

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't much on this particular subject. Is it possible?

推荐答案

您需要设置窗体的的minimumSize MAXIMUMSIZE 属性两种尺寸不同高度,但宽度相等。

You need to set the form's MinimumSize and MaximumSize properties to two sizes with different heights but equal widths.

如果您不想水平调整光标在所有出现,你将会需要处理的<一个href=\"http://msdn.microsoft.com/en-us/library/ms645618%28VS.85%29.aspx\"><$c$c>WM_NCHITTEST消息是这样的:

If you don't want the horizontal resize cursor to appear at all, you'll need to handle the WM_NCHITTEST message, like this:

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.Left || result == HitTest.Right)
                m.Result = new IntPtr((int)HitTest.Caption);
            if (result == HitTest.TopLeft || result == HitTest.TopRight)
                m.Result = new IntPtr((int)HitTest.Top);
            if (result == HitTest.BottomLeft || result == HitTest.BottomRight)
                m.Result = new IntPtr((int)HitTest.Bottom);

            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
}

这篇关于垂直(只)可调大小的窗口在C#中形成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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