更新时间:2023-11-05 11:42:52
试试这个,你必须导入System.Windows.Forms
和System.Reflection
Try this, you have to import System.Windows.Forms
and System.Reflection
首先将表单名称放入strCreatedFromButton
然后找到它.
First get the form name into the strCreatedFromButton
then find it.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim strCreatedFromButton As String = "Form3"
Dim frm As New Form
frm = DirectCast(CreateObjectInstance(strCreatedFromButton), Form)
frm.Show()
End Sub
Public Function CreateObjectInstance(ByVal objectName As String) As Object
Dim obj As Object
Try
If objectName.LastIndexOf(".") = -1 Then
objectName = [Assembly].GetEntryAssembly.GetName.Name & "." & objectName
End If
obj = [Assembly].GetEntryAssembly.CreateInstance(objectName)
Catch ex As Exception
obj = Nothing
End Try
Return obj
End Function