Dim F1 As New Datasystem.Form2 '實例化窗體
我們提供的服務(wù)有:網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、即墨ssl等。為1000多家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的即墨網(wǎng)站制作公司
For Each na As Form In Application.OpenForms '打開窗體的集合
If na.ProductName = F1.ProductName AndAlso na.Name = F1.Name 0 Then '判斷程序集的產(chǎn)品名稱和窗體名稱是否已存在打開的窗體中
If na.WindowState = FormWindowState.Minimized Then '判斷窗體是否最小化
na.WindowState = FormWindowState.Normal '還原窗體
End If
na.Activate() '激活窗體
Return '返回
End If
Next
F1.Show() '如果沒有打開的窗體中未找到,重新打開窗體
Imports System.Runtime.InteropServices
Module Module1
Sub Main()
Dim instance As Process = RunningInstance()
If instance IsNot Nothing Then
ShowWindowAsync(instance.MainWindowHandle, 3) '調(diào)用api函數(shù),正常顯示窗口
Return
End If
Dim F1 As New Form1
Application.Run(F1) '顯示窗體
End Sub
DllImport("User32.dll")
Public Function ShowWindowAsync(ByVal hWnd As System.IntPtr, ByVal cmdShow As Integer) As Boolean
End Function
Private Function RunningInstance() As Process '返回進程中已經(jīng)打開的程序
Dim current As Process = Process.GetCurrentProcess()
Dim processes As Process() = Process.GetProcessesByName(current.ProcessName)
For Each process As Process In processes
If process.Id current.Id Then
If process.MainModule.FileName = current.MainModule.FileName Then
Return process
End If
End If
Next
Return Nothing
End Function
End Module
這個提供進程即可以判斷程序是否已經(jīng)啟動
這個是最一般的方法了
希望能幫到你