基督徒,你的解決方案給我帶來了正確的方式,但它缺乏像我一樣愚蠢和懶惰的複製粘貼代碼! 在這裏,我們去,如果你取消註釋的評論部分,你可以移動除了邊界周圍的窗口。
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;
}
});