2
我試圖根據doubleclick事件上選定的樹狀節點節點啓動特定窗體。我需要用來啓動表單的代碼有點笨重,因爲我必須確保表單不會丟棄,並且在啓動新實例之前表單尚未打開。我希望所有這些檢查發生在函數末尾的一個地方,這意味着我必須能夠在最後將正確的表單類型傳遞給代碼。我試圖用System.Type來做到這一點,但似乎沒有工作。請有人指出我正確的方向嗎?使用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
嘿,只要你有,我可以把它從那裏邏輯。我不知道Activator類。它效果很好。謝謝。 – 2010-06-07 17:16:44