Vic*_*tor 3 c# forms windows resize winforms
可能重复:
在C#中形成垂直(仅)可调整大小的窗口
我有一个案例,我需要允许用户只是水平调整窗体大小.表单的最大宽度是x
.我怎样才能做到这一点?
将MaximumSize和MinimumSize设置为相同的高度,但可变宽度.
为此,调整大小光标不会出现在顶部或底部:
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
}
Run Code Online (Sandbox Code Playgroud)
复制和修改代码:在C#中垂直(仅)可调整大小的窗体