macca,
If you know the type of the control, you can easily create an instance
of it through the static CreateInstance method on the Activator class.
Additionally, since most classes that derive from Control have parameterless
constructors (they should, at least), you don't need to pass anything.
If you have custom controls which require parameters to be called to the
constructor, then you will have to call the overload of CreateInstance which
will take those parameters.
Once you create the control, you can cast the return value to Control,
which will allow you easily modify the common properties (size, location,
etc, etc) and access the typical events (click, double click, etc, etc).
Again, if you have specific events you want to hook up to, you will have
to cast to an instance of the appropriate control, or use reflection to
connect the event. Of course, if you have a bunch of custom controls but
the specific functionality they expose is consistent for each of your custom
controls, an interface might be in order (or a base class they all derive
from) which you can cast to, to make it easier.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"macca" <as****@dsl.pipex.com> wrote in message
news:dM********************@pipex.net...
Hi,
I am writing a GUI application. It will have a number of user defined
controls( I plan to use/create a user defined control that will output
alarm states that the user can also select and will open a dialog to give
more detailed information) .
The number of controls on the main GUI will vary from client site to
client site. I would therefore like to populate the dialog with these
controls dynamically.
e.g the number of controls to be put on the dialog comes from a
configuration file or the database.
I'd appreciate any help on how i put the user defined controls on the form
dynamically and how to manipulate the controls such as catching the click
event on them etc if they havent been put on the form at design time,
Thanks In Advance,
Macca