我正在尝试根据双击事件上树视图的选定节点启动特定表单。我需要用来启动表单的代码有点庞大,因为我必须确保在启动新实例之前表单没有被释放,并且表单还没有打开。我希望所有这些检查都发生在函数末尾的一个地方,这意味着我必须能够在最后将正确的表单类型传递给代码。我正在尝试使用 System.Type 执行此操作,但这似乎不起作用。有人可以指出我正确的方向吗?
With TreeView.SelectedNode
Dim formType As Type
Select Case .Text
Case "Email to VPs"
formType = EmailForm.GetType()
Case "Revise Replacers"
formType = DedicatedReplacerForm.GetType()
Case "Start Email"
formType = EmailForm.GetType()
End Select
Dim form As formType
Dim form As formType
Try
form = CType(.Tag, formType)
If Not form.IsDisposed Then
form.Activate()
Exit Sub
End If
Catch ex As NullReferenceException
'This will error out the first time it is run as the form has not yet
' been defined.
End Try
form = New formType
form.MdiParent = Me
.Tag = form
CType(TreeView.SelectedNode.Tag, Form).Show()
End With