//picDragFlag是一個圖片控件,爲其添加鼠標移動事件
private void picDragFlag_MouseMove(object sender, MouseEventArgs e)
{
//當窗體達到最小時,則不能再拉伸
if (e.Button == MouseButtons.Left && this.Width>180&& this.Height>180)
{
this.Width += e.Location.X;
this.Height += e.Location.Y;
}//當達到最小時,可以拉伸
else if (e.Button == MouseButtons.Left && e.X > 0 && e.Y > 0)
{
this.Width += e.Location.X;
this.Height += e.Location.Y;
}
}
e.X與e.Y
//
// 摘要:
// 獲取鼠標在產生鼠標事件時的 x 座標。
//
// 返回結果:
// 鼠標的 X 座標(以像素爲單位)。
我發現它返回的應該是以鼠標單擊的控件的左上角爲原點,鼠標單擊的地方的座標(是個相對座標)。