2

我有以下代码允许我的控制台应用程序使用图标进入托盘:

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 来检测按下了哪个鼠标按钮?

4

1 回答 1

1

您需要做的是更改行Sub iconClicked以使用 MouseEventArgs 而不是 EventArgs; 像这样:

Private Sub iconClicked(ByVal sender As Object, ByVal e As MouseEventArgs)

您已经这样做了,您可以使用e.Button它来确定用户按下了哪个按钮。

于 2012-03-31T00:11:23.463 回答