Load User control by class name

L

Lou

How do i load a user control by class name in a windows application.
I see asp has a LoadControl function. Is there anything like taht for a
windows app

Something like:
UserControl uc = Load(MyControl.MyClass)

-Lou
 
F

Family Tree Mike

Lou said:
How do i load a user control by class name in a windows application.
I see asp has a LoadControl function. Is there anything like taht for a
windows app

Something like:
UserControl uc = Load(MyControl.MyClass)

-Lou

Is this what you are after?

Type t = Type.GetType("AppName.UserControl1");
UserControl o = (UserControl) Activator.CreateInstance(t);
Controls.Add(o);
 
L

Lou

I was hoping that would work. That is EXACTLY what I needed but variable 't"
always comes back null.

string Filename = Application.StartupPath + \\Mytest.dll;

Assembly Asm = Assembly.LoadFile(Filename)

Type t = Type.GetType("MyNamespace.MyClass");



t is always null!!!!!!



-Louie
 

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