[英]picturebox click event fires before the picturebox's contextmenu menuitem click
我有一個PictureBox.Click事件,我也有一個PictureBox.ContextMenu - 當我點擊上下文菜單中的菜單項時,它首先觸發PictureBox.Click事件,然后觸發附加到菜單項的事件。
這不是我想要的。 有沒有辦法只觸發菜單項事件(或至少,首先)?
如果沒有e.Handled
參數,您可以使用標志中止Click
代碼:
bool flag = false;
private void pb_target_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
Console.WriteLine("pb_target_MouseDown RIGHT");
flag = true;
}
else flag = false;
}
private void pb_target_MouseClick(object sender, MouseEventArgs e)
{
if (flag) { flag = false; return; }
Console.WriteLine("pb_target_MouseClick");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.