Dynamically adding and later referencing control
This is something that was asked how to do in one of the forums I post help in.
Basically the user wanted to know how to dynamically add controls to your form and then refer to them later in the program. The following code gives you an example of how you are able to achieve this;
As you can see in the Form1_Load event we are creating a new TextBox and adding it to the collection of controls on the form, then on the Button1_Click event we are looking in the collection of controls for the form, getting the control with the name txtTest and converting it to a TextBox (explicit conversions are a good thing). Once we have the appropriate TextBox we then set it's Text property to "Hello World".
Last Updated (Wednesday, 04 August 2010 13:27)


