Private Function LoadUserControl(ByVal FormName As String) As UserControl
Dim ProjectName As String =
Reflection.Assembly.GetExecutingAssembly.GetName.Name
Try
Dim tyOfStringVariable As Type = Type.GetType(ProjectName & "." &
FormName)
Dim ucObject As Object = Activator.CreateInstance(tyOfStringVariable)
'DirectCast(ucObject, UserControl).StartPosition = FormStartPosition.CenterParent
'DirectCast(ucObject, Form).ShowDialog()
Return DirectCast(ucObject, UserControl)
Catch ex As Exception
' TODO
Throw New Exception("UserControl Not Exist!")
End Try
Return Nothing
End Function
2011年6月22日 星期三
2011年6月10日 星期五
有關於單一執行個體
在vb裡面可以勾選『單一執行個體』,但是小弟在Server 2008 R2 X64 某些客戶機器底下,發現這個功能完全破功,只好用手動的在程式裡面加上功能
在Form load裡面
Dim intTimes As Integer
Dim strMeName() As String
Dim strName As String
intTimes = 0
'取出名字,包涵檔名路徑
strMeName = Split(Application.ExecutablePath, "\")
'真正的名字是在最後一個
strName = strMeName(strMeName.Length - 1).ToUpper
'不要.exe結尾
strName = Split(strName, ".EXE")(0)
'偵測有無執行過了
For Each p As Process In Process.GetProcesses()
Try
For Each m As ProcessModule In p.Modules
If Mid(m.ModuleName, 1, strName.Length).ToUpper = strName Then
intTimes = intTimes + 1
End If
Next
Catch ex As Exception
End Try
Next
Try
'如果有兩個人,就離開
If intTimes > 1 Then
'自殺
'離開並關閉執行緒
Environment.Exit(Environment.ExitCode)
Application.Exit()
End If
Catch ex As Exception
End Try
這樣無論OS版本為何,幾個User登入,都可以確保只有一隻程式在跑
在Form load裡面
Dim intTimes As Integer
Dim strMeName() As String
Dim strName As String
intTimes = 0
'取出名字,包涵檔名路徑
strMeName = Split(Application.ExecutablePath, "\")
'真正的名字是在最後一個
strName = strMeName(strMeName.Length - 1).ToUpper
'不要.exe結尾
strName = Split(strName, ".EXE")(0)
'偵測有無執行過了
For Each p As Process In Process.GetProcesses()
Try
For Each m As ProcessModule In p.Modules
If Mid(m.ModuleName, 1, strName.Length).ToUpper = strName Then
intTimes = intTimes + 1
End If
Next
Catch ex As Exception
End Try
Next
Try
'如果有兩個人,就離開
If intTimes > 1 Then
'自殺
'離開並關閉執行緒
Environment.Exit(Environment.ExitCode)
Application.Exit()
End If
Catch ex As Exception
End Try
這樣無論OS版本為何,幾個User登入,都可以確保只有一隻程式在跑
訂閱:
文章 (Atom)