2

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?

Ciaran Donoghue
  • 800
  • 3
  • 22
  • 46
StealthRT
  • 10,108
  • 40
  • 183
  • 342

1 Answers1

1

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.

Tom
  • 4,422
  • 3
  • 24
  • 36