我有以下代码,允许我的控制台应用程序使用图标转到托盘:
Sub Main()
Dim tray As New NotifyIcon()
tray.Icon = My.Resources.phoneIcon
tray.Text = "Left Click to show console window"
tray.Visible = True
AddHandler tray.Click, AddressOf iconClicked
ShowWindow(int, False)
System.Windows.Forms.Application.Run()
End Sub
Private Sub iconClicked(ByVal sender As Object, ByVal e As EventArgs)
if mouseLeft then
ShowWindow(int, True)
else
ShowWindow(int, False)
end if
End Sub
它还允许在左键单击托盘图标时重新启动控制台。问题是,我需要能够右键单击以将其取回。
如何使用ByVal e As EventArgs或ByVal sender As Object来检测按下了哪个鼠标按钮?
答案 0 :(得分:1)
您需要做的是更改Sub iconClicked
的行以使用MouseEventArgs而不是EventArgs;像这样:
Private Sub iconClicked(ByVal sender As Object, ByVal e As MouseEventArgs)
您已经完成了这项工作,您可以使用e.Button
找出用户按下的按钮。