How can I add a control to a Window Form at runtime
To add a control at runtime, you do three steps:
- 1. Create the control
- 2. Set control properties
- 3. Add the control to the Form’s Controls collection
In general, if you need help on exactly what code you need to add, just look at the code generated by the designer when you add the control at design time. You can generally use the same code at runtime.
Here are code snippets that create a textBox at runtime.