ieg
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</Locatio nXY>
</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.TextB ox();
is what I need to create but I can't work out how to use txtAndy instead of txtbox
ctlname = new System.Windows.Forms.TextB ox();
will obviously fail
Hope someone can help
regards
andy
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</Locatio
</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.TextB
is what I need to create but I can't work out how to use txtAndy instead of txtbox
ctlname = new System.Windows.Forms.TextB
will obviously fail
Hope someone can help
regards
andy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks - you were spot on with the solution.
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.TextB
this.txtbox.Name = "txtAndy";