[Vb.net] determines whether the form has been opened. vb.net form
1. Use OpenForms
If my. Application. OpenForms. Item ("FormName") isnot nothing then search do something hereelsedo something here end if
2. Use FindWindow API
First, obtain a form handle (using FindWindow), then use IsWindowVisible to determine whether the form is displayed, and an IsIconic to determine whether the form has been minimized.
You can simply find the relevant usage method. The following is the usage Declaration of the three functions:
Private Declare Function FindWindow Lib "user32" Alias "find0000wa" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) as LongPrivate Declare Function IsIconic Lib "user32" Alias "IsIconic" (ByVal hwnd As Long) As Long example: Dim I As Long, J As Long, K As LongI = FindWindow (vbNullString, "my programs") 'I is 0, indicating that "my programs" are not running, otherwise it is the program handle J = IsWindowVisible (I) 'J -- if the window is visible, TRUE (non-zero) K = IsIconic (I) 'is returned to determine whether the window has been minimized. If the value is non-zero, the window is successful. If the value is zero, the window fails.
3. Use Process
Dim myProcesses As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("TrackRecorder") If myProcesses.Length > 1 Then MessageBox.Show("TrackRecorder.exe has run.") Windows.Forms.Application.Exit() End If