开发者

How can one get a ContextMenuStrip to show on left click of a NotifyIcon?

开发者 https://www.devze.com 2023-01-13 21:27 出处:网络
I have a ContextMenuStrip assigned to a NotifyIcon and this works wi开发者_开发百科th the right click fine.

I have a ContextMenuStrip assigned to a NotifyIcon and this works wi开发者_开发百科th the right click fine.

How may I wire up the mouse-click event to tell the NotifyIcon to show its ContextMenuStrip?

private void taskbarIcon_MouseClick(object sender, MouseEventArgs e)
{
    switch (e.Button)
    {
        case MouseButtons.Left:
            // What could I use here?
            break;
        default:
            break;
    }
}


You should be able to use the following code:

if (e.Button == MouseButtons.Left)
{
   MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", 
            BindingFlags.Instance |BindingFlags.NonPublic);
    mi.Invoke(taskbarIcon, null);
}

Here's a good thread about the subject at MSDN site.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号