【备份】托盘控件图标左键单击显示菜单

Private Sub NotifyIcon1_MouseClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseClick
        Select Case e.Button
            Case Windows.Forms.MouseButtons.Left
                ' 这个方法不能很好解决内容菜单位置问题
                ' 并且对菜单外的鼠标操作没有取消菜单反应
                'ContextMenuStrip1.Show(Cursor.Position)

                ' 利用反射动态调用内容菜单的内部方法,完美解决所有问题
                Dim t As Type = GetType(NotifyIcon)
                Dim mi As Reflection.MethodInfo = t.GetMethod("ShowContextMenu", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance)
                mi.Invoke(NotifyIcon1, Nothing)

            Case Windows.Forms.MouseButtons.Right

            Case Windows.Forms.MouseButtons.Middle

        End Select
    End Sub

 

posted @ 2013-01-28 13:02 二笔青年 阅读(...) 评论(...) 编辑 收藏