Creating Forms control using Activator

  • Thread starter Thread starter KK
  • Start date Start date
K

KK

Hi All
I need to create a windows form control(from System.Windows.Forms.dll
assembly) dynamically using Activator.How do I achieve this?Sample code is
much more helpful.

Thanks in advance

Regards
Krishna
 
If you have a reference to the System.Windows.Forms assembly you can use:

object o = Activator.CreateInstance(typeof(System.Windows.Forms.Control));

If you don;t you need to use:

Type t = Type.GetType("System.Windows.Forms.Control, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
object o = Activator.CreateInstance(t);

Incidently its a bit unusual to want to create aninstance of the base Control class, what are you trying to do

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

Hi All
I need to create a windows form control(from System.Windows.Forms.dll
assembly) dynamically using Activator.How do I achieve this?Sample code is
much more helpful.

Thanks in advance

Regards
Krishna
 
Basically I'm trying to create controls like TextBox,Panel and Splitter like
controls dynamically and attaching them to my form.These control's
properties are defined in an XML file such as alignment,docking styles and
colors(like XAML for Longhorn).
Thanks for your kind reply..
Regards
Krishna

Richard Blewett said:
If you have a reference to the System.Windows.Forms assembly you can use:

object o = Activator.CreateInstance(typeof(System.Windows.Forms.Control));

If you don;t you need to use:

Type t = Type.GetType("System.Windows.Forms.Control,
System.Windows.Forms, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089");
object o = Activator.CreateInstance(t);

Incidently its a bit unusual to want to create aninstance of the base
Control class, what are you trying to do
 

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

Back
Top