標籤:
1.使用OpenForms
if my.Application.OpenForms.Item("FormName") isnot nothing then搜尋do something hereelsedo something here end if
2.使用FindWindow API
首先取得一個表單的控制代碼(使用FindWindow),然後使用IsWindowVisible判斷此表單是否顯示,還有一個IsIconic判斷表單是否已經最小化。
相關使用方法你簡單尋找一下就可以了,下面是三個函數的使用聲明:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (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相關的使用樣本:Dim I As Long, J As Long, K As LongI = FindWindow(vbNullString, "我的程式")‘I為0表示“我的程式”沒有運行,否則它是程式的控制代碼J = IsWindowVisible(I)‘J--如視窗可見則返回TRUE(非零)K = IsIconic(I)‘判斷視窗是否已最小化,非零表示成功,零表示失敗
3.使用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
[vb.net]判斷表單是否已開啟