2011-03-21 20 views

回答

6

形式是不是绝对必要的。您可以实例化的NotifyIcon和使用,而无需创建一个表单:

Public Class AppContext 
    Inherits ApplicationContext 

    Private notifyIcon As NotifyIcon 
    Private appActive As Boolean 

    Public Sub New() 
     AddHandler Application.ApplicationExit, AddressOf OnApplicationExit 

     notifyIcon = New NotifyIcon() 
     notifyIcon.Icon = My.Resources.ActiveIcon 
     notifyIcon.Text = "The app is active." 

     AddHandler notifyIcon.MouseClick, AddressOf OnIconMouseClick 

     appActive = True 
     notifyIcon.Visible = True 

    End Sub 

    Private Sub OnApplicationExit(ByVal sender As Object, ByVal e As EventArgs) 
     If notifyIcon IsNot Nothing Then 
      notifyIcon.Dispose() 
     End If 
    End Sub 

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

     If e.Button = MouseButtons.Left Then 
      appActive = Not appActive 
      notifyIcon.Icon = If(appActive, My.Resources.ActiveIcon, My.Resources.InactiveIcon) 
      notifyIcon.Text = If(appActive, "The app is active.", "The app is not active.") 
     Else 
      If MsgBox("Do you want to Exit?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then 
       notifyIcon.Visible = False 
       ExitThread() 
      End If 
     End If 
    End Sub 

End Class 

,然后开始从子主你的应用程序:

Public Module EntryPoint 
    Public Sub Main() 
     Dim ctx As New AppContext() 
     Application.Run(ctx) 
    End Sub 
End Module 
+0

克里斯,非常感谢你。这正是我所期待的。这工作得很好,并解决了我遇到的其他一些问题。谢谢! – avword 2011-03-27 21:50:59

0

只要把形式透明,并将其调整到1×1 .. 并添加NotifyIcon的..

而且在窗体的Load事件做到这一点:

NotifyIcon.Visible =真

然后做任何你想要的东西..

你可以创建一个上下文菜单条(当你右键点击它时的一个菜单) PS:如果你这样做,你需要去NotifyIcon属性并设置上下文菜单条您创建..

希望它可以帮助你..

相关问题