I have the following code that allows my console app to go to the tray with an icon:

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

It also allows the console to be brought back up when left-clicking on the tray icon. The problem is, I need to be able to right-click to take it back down.

How can I use the ByVal e As EventArgs or ByVal sender As Object to detect which mouse button is pressed?

有帮助吗?

解决方案

What you need to do is change the line of the Sub iconClicked to use MouseEventArgs and not EventArgs; like so:

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

One you have done that, you can use e.Button to figure out which button the user pressed.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top