2012-03-30 62 views
2

我有下面的代碼,使我的控制檯應用程序去托盤圖標:被帶到vb.net控制檯應用程序

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作爲EventArgs或ByVal sender作爲Object來檢測按下了哪個鼠標按鈕?

回答

1

您需要做的是將Sub iconClicked的行更改爲使用MouseEventArgs而不是EventArgs;像這樣:

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

一,你這樣做,你可以使用e.Button找出用戶按下哪個按鈕。

+0

太棒了,工作。謝謝,湯姆! – StealthRT 2012-03-31 01:02:21