GetFormByName for compact framework ?

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
 
X

Xin Yan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top