在我的程序中,我使用WndProc覆盖来阻止窗体调整大小。问题是,当您将指针移动到窗体边缘时,光标仍然存在。
有没有办法隐藏这个光标?
有没有办法隐藏这个光标?
FormBorderStyle
属性呢?这样,您也无需使用 WndProc
了。using System;
using System.Windows.Forms;
using System.Drawing;
class Test
{
[STAThread]
static void Main(string[] args)
{
Button button = new Button
{
Text = "Toggle border",
AutoSize = true,
Location = new Point(20, 20)
};
Form form = new Form
{
Size = new Size (200, 200),
Controls = { button },
FormBorderStyle = FormBorderStyle.Fixed3D
};
button.Click += ToggleBorder;
Application.Run(form);
}
static void ToggleBorder(object sender, EventArgs e)
{
Form form = ((Control)sender).FindForm();
form.FormBorderStyle = form.FormBorderStyle == FormBorderStyle.Fixed3D
? FormBorderStyle.Sizable : FormBorderStyle.Fixed3D;
}
}
我已经找到了一种使用WndProc的方法,感谢Lasse给我的链接。感谢您的回复Jon,但这并不完全是我想要的。对于那些想知道我是如何做到的人,我使用了以下方法:
protected override void WndProc(ref Message m)
{
const int WM_NCHITTEST = 0x0084;
switch (m.Msg)
{
case WM_NCHITTEST:
return;
}
base.WndProc(ref m);
}
只需设置FormBorderStyle即可。你为什么要使用WndProc来做这件事呢?