托盘应用程序无法正常显示
Tray application not displaying properly
下面是我正在使用的框架的代码。我遇到的问题是图标不会显示在系统托盘中,除非包含注释代码。最奇怪的部分是 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
正如 Hans 所指出的,您需要设置 notifyicon1 的图标 属性,这是您在 With 语句中所做的,但不是在上面的代码中。
将 Icon = My.Resources.icon_4
更改为 notifyicon1.Icon = My.Resources.icon_4
,因为您似乎没有在任何地方使用图标 属性。
下面是我正在使用的框架的代码。我遇到的问题是图标不会显示在系统托盘中,除非包含注释代码。最奇怪的部分是 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
正如 Hans 所指出的,您需要设置 notifyicon1 的图标 属性,这是您在 With 语句中所做的,但不是在上面的代码中。
将 Icon = My.Resources.icon_4
更改为 notifyicon1.Icon = My.Resources.icon_4
,因为您似乎没有在任何地方使用图标 属性。