因为 NotifyIcon 控件只能使用鼠标右键才能显示菜单,那如何让其支持鼠标左键显示菜单呢???
Private Sub NotifyIcon1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseClick
Select Case e.Button
Case Windows.Forms.MouseButtons.Left
' 这个方法不能很好解决内容菜单位置问题
' 并且对菜单外的鼠标操作没有取消菜单反应
'ContextMenuStrip1.Show(Cursor.Position)
' 利用反射动态调用内容菜单的内部方法,完美解决所有问题
Static mi As Reflection.MethodInfo = GetType(NotifyIcon).GetMethod("ShowContextMenu", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance)
mi.Invoke(NotifyIcon1, Nothing)
Case Windows.Forms.MouseButtons.Right
Return
Case Windows.Forms.MouseButtons.Middle
End Select
End Sub