GetFormByName for compact framework ?

  • Thread starter Thread starter Mobile Boy 36
  • Start date Start date
M

Mobile Boy 36

Does someone know a way to cast a string to a form ?

Or an working alternative for the compact framework:

Function GetFormByName(ByVal FormName As String) As Form
Dim Fullname As String = Application.ProductName & "." & FormName
Return Activator.CreateInstance(Type.GetType(Fullname, True, True))
End Function
 
hi,

Application.ProductName is not supported in .Net compact framework, so you
need to replace it with your namespace name, such as
"SmartDeviceApplication1". Also Type.GetType throws unsupported exception
if you pass in 3 parameters. I modified your function and it works on
pocket pc.

Function GetFormByName(ByVal FormName As String) As Form
Dim Fullname As String = "SmartDeviceApplication1" & "." & FormName
Return Activator.CreateInstance(Type.GetType(Fullname))
End Function

When you use this function, be sure to pass FormName in the right case.

Hope this helps.

Xin
 
Back
Top