在尝试启动单实例应用程序的新实例时显示隐藏的应用程序

Show hidden application on trying to launch a new instance of a single instance application

我正在 VB.NET 中开发单个实例应用程序,当我们最小化表单时它会隐藏:

Private Sub Form_Resize(sender As Object, e As EventArgs) Handles Me.Resize
    If Me.WindowState = FormWindowState.Minimized Then
        Me.Visible = False
    End if
End Sub

然后,如果我尝试再次启动它,它不会打开,因为它已经 运行(到目前为止,还不错)。
是否可以让它只在这个舞台上可见?我的意思是,如果我尝试在应用程序已经 运行 时启动它,我可以只让应用程序可见吗?
我想这是可以做到的,因为有些应用程序具有这种确切的行为。

在您的 WinForms 项目属性中 select“查看应用程序事件”(我的项目 -> 应用程序 -> 查看应用程序事件)。从那里您可以看到在应用程序开始和结束时触发的事件。其中之一是 StartupNextInstance 事件处理程序。在这里您应该可以再次显示您的表单。

根据文档:

A single-instance application raises the StartupNextInstance event when you attempt to restart the application when it is already active. When a single-instance application starts for the first time, it raises the Startup event. For more information, see Startup.

StartupNextInstance Documentation