我有一个表单,它的 FormBorderStyle 设置为 Sizable。这会在右下角创建抓地力。调整窗口大小的唯一方法是将鼠标准确地放在边缘。我想知道是否有一种方法可以更改光标以在用户将鼠标悬停在手柄上时调整大小,或者我是否可以增加它允许您在边缘调整大小的范围,这样您就不会您的鼠标位置必须如此精确。
问问题
157 次
2 回答
1
于 2015-05-29T16:26:50.773 回答
1
这是一个类似的 SO 问题的链接。这家伙没有国界,所以你可能需要做一些不同的事情,但应该给你一个进入的方向。我将在这里重新粘贴他的代码以完成:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.ResizeRedraw, true);
}
private const int cGrip = 16; // Grip size
private const int cCaption = 32; // Caption bar height;
protected override void OnPaint(PaintEventArgs e) {
Rectangle rc = new Rectangle(this.ClientSize.Width - cGrip, this.ClientSize.Height - cGrip, cGrip, cGrip);
ControlPaint.DrawSizeGrip(e.Graphics, this.BackColor, rc);
rc = new Rectangle(0, 0, this.ClientSize.Width, cCaption);
e.Graphics.FillRectangle(Brushes.DarkBlue, rc);
}
protected override void WndProc(ref Message m) {
if (m.Msg == 0x84) { // Trap WM_NCHITTEST
Point pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16);
pos = this.PointToClient(pos);
if (pos.Y < cCaption) {
m.Result = (IntPtr)2; // HTCAPTION
return;
}
if (pos.X >= this.ClientSize.Width - cGrip && pos.Y >= this.ClientSize.Height - cGrip) {
m.Result = (IntPtr)17; // HTBOTTOMRIGHT
return;
}
}
base.WndProc(ref m);
}
}
于 2015-05-29T16:58:43.287 回答