基督徒,你的解决方案给我带来了正确的方式,但它缺乏像我一样愚蠢和懒惰的复制粘贴代码! 在这里,我们去,如果你取消注释的评论部分,你可以移动除了边界周围的窗口。
private void Action_LMouseDownAndMove(object sender, MouseEventArgs e)
{
Point mousePosition = this.PointToClient(System.Windows.Forms.Cursor.Position);
const int WM_NCLBUTTONDOWN = 0xA1;
//const int HT_CAPTION = 0x2;
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
if (mousePosition.X < 20)
{
if (mousePosition.Y < 20)
SendMessage(Handle, WM_NCLBUTTONDOWN, 13, 0);
else if (mousePosition.Y > this.Size.Height - 20)
SendMessage(Handle, WM_NCLBUTTONDOWN, 16, 0);
else
SendMessage(Handle, WM_NCLBUTTONDOWN, 10, 0);
}
else if (mousePosition.X > this.Size.Width - 20)
{
if (mousePosition.Y < 20)
SendMessage(Handle, WM_NCLBUTTONDOWN, 14, 0);
else if (mousePosition.Y > this.Size.Height - 20)
SendMessage(Handle, WM_NCLBUTTONDOWN, 17, 0);
else
SendMessage(Handle, WM_NCLBUTTONDOWN, 11, 0);
}
else if (mousePosition.Y < 20)
SendMessage(Handle, WM_NCLBUTTONDOWN, 12, 0);
else if (mousePosition.Y > this.Size.Height - 20)
SendMessage(Handle, WM_NCLBUTTONDOWN, 15, 0);
//else
// SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
根据您的喜好更改20像素值。我不是100%肯定左/右和上/下具有完全相同的调整大小区域,或者如果你知道我的意思,是否需要19/21 ... if/else树有一些减少的可能性, 我知道。而不是20我应该使用一个常数。
要更改光标显示他可以调整我使用下面的代码的用户,它只是一个MouseMove事件处理程序:
this.pictureBox.MouseMove += new MouseEventHandler((a, e) =>
{
Point h = this.PointToClient(System.Windows.Forms.Cursor.Position);
if (h.X < 20)
{
if (h.Y < 20)
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeNWSE;
}
else if (h.Y > this.Size.Height - 20)
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeNESW;
}
else
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeWE;
}
}
else if (h.X > this.Size.Width - 20)
{
if (h.Y < 20)
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeNESW;
}
else if (h.Y > this.Size.Height - 20)
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeNWSE;
}
else
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeWE;
}
}
else if (h.Y < 20)
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeNS;
}
else if (h.Y > this.Size.Height - 20)
{
pictureBox.Cursor = System.Windows.Forms.Cursors.SizeNS;
}
else
{
pictureBox.Cursor = System.Windows.Forms.Cursors.Default;
}
});