Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 隐藏程序并从“显示隐藏”图标重新打开它_Vb.net - Fatal编程技术网

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

你发布了一些代码,你能告诉我们什么有效,什么无效吗?