2012-03-30 111 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