0
我有一個沒有邊框,標題欄,菜單等的Windows窗體。我希望用戶能夠按住CTRL鍵,左鍵單擊表單上的任意位置並拖動它,移動。任何想法如何做到這一點?我想這一點,但它閃爍,不少:如何在按住鼠標的同時移動表單?
private void HiddenForm_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
this.SuspendLayout();
Point xy = new Point(this.Location.X + (e.X - this.Location.X), this.Location.Y + (e.Y - this.Location.Y));
this.Location = xy;
this.ResumeLayout(true);
}
}
這很好,只是好奇它在做什麼? – esac 2009-10-06 23:35:47
它是在默認的窗口過程中,在窗口的「標題」非客戶區發生鼠標停止事件。 儘管如果你想要正確的實現,你應該添加你自己的消息處理鉤子並且處理WM_NCHITTEST消息來返回HT_CAPTION你想要啓用表單拖動的窗體區域。 – 2009-10-07 00:01:06
+1甜蜜......你贏了:)我甚至沒有得到正確的數學LOL。 – 2009-10-07 00:59:03