關於動態調用窗體的問題

關於動態調用窗體的問題:
想要完成的功能:在數據庫中用一個字段存放要打開的窗體名及關鍵字,當點擊關鍵字時,系統打開相應的窗體,這樣只需對數據庫進行管理就可以動態改變要打開的窗體,也便於今後擴充!
問題點:我根據關鍵字找到了窗體名"Form1"(是一個字符變量FormName),現在我應怎樣實例化它後並打開?
我所實驗過的方法:FormName=ctype(FormName,Form)
dim Myobj as new Form=FormName
Myobj.Show()
錯誤提示:字符串沒有Show方法 & 字符中不能轉換為Form

---------------------------------------------------------------

搞定,用反射:
Dim a As Reflection.Assembly = Reflection.Assembly.LoadFrom("remoting_server.exe")
' Get the type names from the assembly.
Dim types2 As Type() = a.GetTypes()
'Dim ms() As Reflection.Module = a.GetModules
'Dim m As Reflection.Module
'For Each m In ms

' If m.Name = "form1" Then

' End If
'Next

Dim t As Type
For Each t In types2
If t.Name = "Form1" Then
Dim frm As Object = Activator.CreateInstance(t)
frm.show()
End If
Next t
---------------------------------------------------------------

mynewpc(水中日月) 的办法高明!我实验了一下,还可以这样改动一下:

Dim a As Reflection.Assembly = Reflection.Assembly.LoadFrom("remoting_server.exe")
改成
Dim a As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly
测试通过。
不过,帖主怎么还不给分?不太好吧? :)

Published At
Categories with Web编程
Tagged with
comments powered by Disqus