[VB.NET]使用Make single instance application實現單一程式執行個體時所發生的怪現象
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize
If Me.WindowState = FormWindowState.Minimized Then
NotifyIcon1.Visible = True
Me.Hide()
End If
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Me.Visible = True
Me.WindowState = 0 '還原
Me.Activate()
Me.TopMost = True
NotifyIcon1.Visible = False
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
NotifyIcon1.Icon = Me.Icon
End Sub
End Class
Public Class Form1
<STAThread> _
Public Shared Sub Main()
Dim isCreated As Boolean
Using m As New Mutex(False, "NotifyIconApp", isCreated)
If Not isCreated Then
Return
End If
Application.Run(New Form1())
End Using
End Sub
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize
If Me.WindowState = FormWindowState.Minimized Then
NotifyIcon1.Visible = True
Me.Hide()
End If
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Me.Visible = True
Me.WindowState = 0 '還原
Me.Activate()
Me.TopMost = True
NotifyIcon1.Visible = False
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
NotifyIcon1.Icon = Me.Icon
End Sub
End Class