首先收集所有的問卷形式爲陣。將您的問題表單命名爲「問題1」,「問題2」或類似的內容,或者爲您的表單設置標籤。然後通過索引找到你的表單,並創建一個實例和ShowDialog,就是這樣。嘗試下面的代碼。
Public Class Form1
Private forms(20) As Type
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim yourFormIndex = 3
Dim frm As Form = Activator.CreateInstance(forms(yourFormIndex))
frm.ShowDialog()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Dim types As Type() = myAssembly.GetTypes()
Dim index As Integer = 1
For Each myType As Object In types
If myType.BaseType.FullName.ToString.ToUpper = "SYSTEM.WINDOWS.FORMS.FORM" Then
If (myType.Name.ToString.StartsWith("Questionary")) Then
forms(index) = myType
index = index + 1
End If
End If
Next
End Sub
End Class
爲了簡單起見,您需要一個主窗體來處理所有其他窗體。如果使用'ShowDialog'而不是'Show',則父窗口將凍結,直到子窗體關閉 –