0
我有一個MenuStrip,我想在窗體上拖動一些東西(然後發生一些事情,例如窗體的背景色正在改變等)。我正在處理MouseDown事件,但事實是,當我單擊ToolStripMenu
中的選項時,會發生同樣的情況(表單的背景色正在改變等)。 我想要的是以某種方式將MouseClick
從MouseDown
中分離出來。更確切地說,當我點擊MenuStrip
的一個選項時,我不希望發生任何事情。如何不在Windows窗體中混淆鼠標點擊和鼠標按下事件?
當我點擊時,MouseDown
事件觸發。除非鼠標光標移動,否則我想忽略它。
private void salmonToolStripMenuItem_MouseDown(object sender, MouseEventArgs e)
{
//gets the cursor position at the moment when mouse down is activated
p1M = Cursor.Position.X;
p2M = Cursor.Position.Y;
//miscare shows if the mouse moved
if (miscare == true)
{
//do things
}
}
private void Rezervare1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void salmonToolStripMenuItem_MouseUp(object sender, MouseEventArgs e)
{
//gets the cursor position to see if it moved
p1m = Cursor.Position.X;
p2m = Cursor.Position.Y;
if (p1M != p1m || p2M != p2m)
{
miscare = true;//it means the cursor moved
}
else miscare = false;
}
你必須告訴我們你的代碼。 –
做到了,對不起。 – Patricia