Generic control creation and setting propertis?

  • Thread starter Thread starter Özden Irmak
  • Start date Start date
Ö

Özden Irmak

Hello,

In my winforms application, i want to be able to create new controls which
their types aren't pre-defined. I know the way :

Dim C as new CheckBox()

which creates a new checkbox control but in my situation I don't have a
knowledge on th type of the component except I only know the class in string
format (like "System.Windows.Forms.CheckBox")

A second goal is to make a generic property setting. At this situation, I
again know the name of the property and the value and trying to find a way
to set the property something like this :

Control.Property("blabla").Value = PropertyValue (This is only for sample
purpse, I know this won't work)

Can somebody point me out about the possibilities of these tasks?

Thanks in advance...

Özden
 
For Object Creation try

object x = [Assembly].GetExecutingAssembly.CreateInstance("CheckBox")

Except you'll probably need to find the assembly that holds the object class
you wish to create.

you can get that from the Type you are trying to create as in

Assembly ass = Type.Assembly
object x = ass.CreateInstance("ObjectName")

For Properties.

System.Reflection.PropertyInfo pi
Type t1 = Object.GetType
pi = t1.getproperty("PropertyName")
pi.setvalue(Object, "PropertyValue")

Hope that helps.
 
Thank you very very much...:)

Rigga said:
For Object Creation try

object x = [Assembly].GetExecutingAssembly.CreateInstance("CheckBox")

Except you'll probably need to find the assembly that holds the object class
you wish to create.

you can get that from the Type you are trying to create as in

Assembly ass = Type.Assembly
object x = ass.CreateInstance("ObjectName")

For Properties.

System.Reflection.PropertyInfo pi
Type t1 = Object.GetType
pi = t1.getproperty("PropertyName")
pi.setvalue(Object, "PropertyValue")

Hope that helps.

Özden Irmak said:
Hello,

In my winforms application, i want to be able to create new controls which
their types aren't pre-defined. I know the way :

Dim C as new CheckBox()

which creates a new checkbox control but in my situation I don't have a
knowledge on th type of the component except I only know the class in string
format (like "System.Windows.Forms.CheckBox")

A second goal is to make a generic property setting. At this situation, I
again know the name of the property and the value and trying to find a way
to set the property something like this :

Control.Property("blabla").Value = PropertyValue (This is only for sample
purpse, I know this won't work)

Can somebody point me out about the possibilities of these tasks?

Thanks in advance...

Özden
 
* "Özden Irmak said:
In my winforms application, i want to be able to create new controls which
their types aren't pre-defined. I know the way :

Dim C as new CheckBox()

which creates a new checkbox control but in my situation I don't have a
knowledge on th type of the component except I only know the class in string
format (like "System.Windows.Forms.CheckBox")

A second goal is to make a generic property setting. At this situation, I
again know the name of the property and the value and trying to find a way
to set the property something like this :

<http://www.google.com/[email protected]>
 
Back
Top