如果右键单击NotifyIcon

时间:2018-03-30 12:44:16

标签: c# winforms right-click notifyicon

如何检测我是否右键单击NotifyIcon?

我尝试了这个但是"按钮"被取消标记。

 private void noi_Click(object sender, EventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                MessageBox.Show("test");
            }
        }

2 个答案:

答案 0 :(得分:0)

NotifyIcon具有ContextMenu属性。使用它。

答案 1 :(得分:0)

ContextMenu不是我想要的。但我找到了一种方法:

private void noi_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                LEFTORRIGHT = "left";
            }
            if (e.Button == MouseButtons.Right)
            {
                LEFTORRIGHT = "right";
            }
        }
    private void noi_Click(object sender, EventArgs e)
        {
            if (LEFTORRIGHT == left)
            {

            }
            if (LEFTORRIGHT == right)
            {

            }
        }