[Vb.net] determines whether the form has been opened. vb.net form

Source: Internet
Author: User

[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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.