Vb.net 隐藏程序并从“显示隐藏”图标重新打开它
我想在关闭程序时隐藏程序以在后台运行。当我点击通知图标时,我希望程序再次显示。提前谢谢。 这是我的密码Vb.net 隐藏程序并从“显示隐藏”图标重新打开它,vb.net,Vb.net,我想在关闭程序时隐藏程序以在后台运行。当我点击通知图标时,我希望程序再次显示。提前谢谢。 这是我的密码 Private Sub Form_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing Dim response As MsgBoxResult playErrorSound() 'Message t
Private Sub Form_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim response As MsgBoxResult
playErrorSound()
'Message that ask user to if his action means to close the application.
response = MsgBox("Do you want to close?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirm")
If response = MsgBoxResult.Yes Then
'Stop timer
Timer1.Stop()
Me.StopWatch.Stop()
'close program
Me.Hide()
Me.ShowInTaskbar = True
ElseIf response = MsgBoxResult.No Then
'Keep form opened
e.Cancel = True
Exit Sub
End If
End Sub
使用NotifyIcon控件
Public Class Form1
Dim WithEvents notify As New NotifyIcon
Sub New()
InitializeComponent()
Dim myIcon As New System.Drawing.Icon("c:\stuff\myicon.ico")
notify.Icon = myIcon
notify.Visible = False
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim response As MsgBoxResult
playErrorSound()
'Message that ask user to if his action means to close the application.
response = MsgBox("Do you want to close?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirm")
If response = MsgBoxResult.Yes Then
'Stop timer
Timer1.Stop()
Me.StopWatch.Stop()
'close program
Me.Hide()
Me.ShowInTaskbar = False
notify.Visible = True
End If
e.Cancel = True
End Sub
Private Sub notify_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles notify.DoubleClick
Me.Show()
Me.ShowInTaskbar = True
notify.Visible = False
End Sub
End Class
你发布了一些代码,你能告诉我们什么有效,什么无效吗?