Link to home
Start Free TrialLog in
Avatar of ieg
iegFlag for United Kingdom of Great Britain and Northern Ireland

asked on

dynamically adding controls to a winform

I am trying to create a data entry application that has an element of user configuration.
An XML file should allow a user to add controls to a winform.
e.g.
<?xml version="1.0" encoding="utf-8" ?>
<!--Defines controls on a form-->
<Form name="TestForm">
<Control type="TextBox" name="txtAndy">
<Size width="100" height="20"></Size>
<LocationXY>51,30</LocationXY>
</Control>
<Control> ...... etc etc etc
</Form>

I can't find a way of creating the control using the "name" in the XML file.
If a variable ctlname holds the string "txtAndy" what command can I use to create the object called txtAndy?

this.txtbox= new System.Windows.Forms.TextBox();
is what I need to create but I can't work out how to use txtAndy instead of txtbox

ctlname = new System.Windows.Forms.TextBox();
will obviously fail

Hope someone can help

regards
andy





Avatar of kris_per
kris_per


I think in your xml "name" is not the name of the variable...its the name for the control..you can set the name for a control like:

this.txtbox= new System.Windows.Forms.TextBox();
this.txtbox.Name = "txtAndy";
ASKER CERTIFIED SOLUTION
Avatar of kris_per
kris_per

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ieg

ASKER

Many thanks - you were spot on with the solution.