下面我有我正在使用的框架的代码。我遇到的问题是除非包含注释代码,否则图标不会显示在系统托盘中。最奇怪的部分是notifyicon1属性的其他代码行将起作用。有人可以帮我理解发生了什么吗?
Public Class Main
Public WithEvents notifyicon1 As New NotifyIcon
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Width = 1200
Height = 850
ShowIcon = True
Me.Text = "V1.0.0.0"
' icon
Icon = My.Resources.icon_4
'set the form properties
BackColor = Color.White
Dim start As New startup()
End Sub
Private Sub Main_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize
If Me.WindowState = FormWindowState.Minimized Then
notifyicon1.Visible = True
Me.Hide()
Icon = My.Resources.icon_4
notifyicon1.Visible = True
notifyicon1.BalloonTipText = "Hi from right system tray"
notifyicon1.ShowBalloonTip(500)
'With notifyicon1
' .Icon = My.Resources.icon_4
' .Visible = True
' .ShowBalloonTip(500)
'End With
End If
End Sub
Private Sub NotifyIcon1_DoubleClick(sender As Object, e As MouseEventArgs) Handles notifyicon1.DoubleClick
Me.Show()
Me.WindowState = FormWindowState.Normal
notifyicon1.Visible = False
End Sub
End Class
答案 0 :(得分:1)
正如汉斯指出的那样,您需要设置notifyicon1的Icon属性,您可以在With语句中进行此属性,但不能在上面的代码中进行。
使用Icon = My.Resources.icon_4
更改notifyicon1.Icon = My.Resources.icon_4
,因为您似乎没有在任何地方使用Icon属性。