[vb.net]判斷表單是否已開啟

來源:互聯網
上載者:User

標籤:

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]判斷表單是否已開啟

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.