468,253 Members | 1,241 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,253 developers. It's quick & easy.

Create form from name

I was using the following code to create a form from its class name. It was
working then at some point I must have broken it, and now have no idea why
it will not work. The CreateInstance method returns <Nothing>

Class MyClass
Function OpenForm(ByVal FormName As String) As Form
Dim obj As Object
obj = Me.GetType.Assembly.CreateInstance(FormName, False)
Return CType(obj,Form)
End Function
End Class

--
Thanks for any help,
Shayne H
Nov 19 '05 #1
3 4292
I've done something just like this just the other day.

I used Activator along with that and used GetExecutingAssembly() instead...

I have the code at work unfortunatly =(
"Shayne H" <shaynehATlycosSPAMGOTOHELLcoDOTuk> wrote in message
news:OO**************@tk2msftngp13.phx.gbl...
I was using the following code to create a form from its class name. It was working then at some point I must have broken it, and now have no idea why
it will not work. The CreateInstance method returns <Nothing>

Class MyClass
Function OpenForm(ByVal FormName As String) As Form
Dim obj As Object
obj = Me.GetType.Assembly.CreateInstance(FormName, False)
Return CType(obj,Form)
End Function
End Class

--
Thanks for any help,
Shayne H

Nov 19 '05 #2
Hello,

"Shayne H" <shaynehATlycosSPAMGOTOHELLcoDOTuk> schrieb:
I was using the following code to create a form from its class name. It was working then at some point I must have broken it, and now have no idea why
it will not work. The CreateInstance method returns <Nothing>


This works for me:

\\\
Dim objNewForm As Object = _
Activator.CreateInstance( _
Type.GetType("MyApplication.SampleForm") _
)
Dim frm As Form = DirectCast(objNewForm, Form)
frm.Show()
///

HTH,
Herfried K. Wagner
--
MVP VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #3
That was a lot simplier than what I did...
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:eY**************@TK2MSFTNGP10.phx.gbl...
Hello,

"Shayne H" <shaynehATlycosSPAMGOTOHELLcoDOTuk> schrieb:
I was using the following code to create a form from its class name. It

was
working then at some point I must have broken it, and now have no idea why it will not work. The CreateInstance method returns <Nothing>


This works for me:

\\\
Dim objNewForm As Object = _
Activator.CreateInstance( _
Type.GetType("MyApplication.SampleForm") _
)
Dim frm As Form = DirectCast(objNewForm, Form)
frm.Show()
///

HTH,
Herfried K. Wagner
--
MVP VB Classic, VB .NET
http://www.mvps.org/dotnet

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by SAN CAZIANO | last post: by
6 posts views Thread by SamIAm | last post: by
15 posts views Thread by lxyone | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.