Connecting Tech Pros Worldwide Forums | Help | Site Map

Creating Forms control using Activator

KK
Guest
 
Posts: n/a
#1: Nov 16 '05
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



Richard Blewett [DevelopMentor]
Guest
 
Posts: n/a
#2: Nov 16 '05

re: Creating Forms control using Activator


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

object o = Activator.CreateInstance(typeof(System.Windows.For ms.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

KK
Guest
 
Posts: n/a
#3: Nov 16 '05

re: Creating Forms control using Activator


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 [DevelopMentor]" <richardb@develop.com> wrote in message
news:e0GTx9csEHA.2144@TK2MSFTNGP10.phx.gbl...[color=blue]
> If you have a reference to the System.Windows.Forms assembly you can use:
>
> object o =[/color]
Activator.CreateInstance(typeof(System.Windows.For ms.Control));[color=blue]
>
> If you don;t you need to use:
>
> Type t = Type.GetType("System.Windows.Forms.Control,[/color]
System.Windows.Forms, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089");[color=blue]
> object o = Activator.CreateInstance(t);
>
> Incidently its a bit unusual to want to create aninstance of the base[/color]
Control class, what are you trying to do[color=blue]
>
> 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[/color]
is[color=blue]
> much more helpful.
>
> Thanks in advance
>
> Regards
> Krishna
>[/color]


Closed Thread