Creating controls dynamically on windows form using visual basic.net
Author: Shahzad Latif
Download Source Code : 569_Creating an Enterprise Services Component.zip
Creating controls dynamically or on-the-fly is very easy in Visual Basic.Net.
This article shows you how the controls can be added on a windows form and how to read these controls latter.
Create a New Visual Basic.Net Project and select Windows Application from the templates.
Add a text box and two button controls on the windows form. Name the controls as txtCount, cmdShowControls, and cmdShowValues.
Add following code in the forms load event
First two lines of code set the initial height and width of the form.
Now, add following code in the Declarations section of the form
Your form, in the start, will show a text box and a button. When you'll click the button after entering a number in the text box, the form will show the text boxes according to the number entered in the field. So, you need to add some code in the click event of the cmdShowControls.
Oh, before that, remember i have created a HashTable object. It'll keep track of all the controls you will be creating dynamically, so that latter on you would be able to check which control was created by your code on-the-fly.
After you have created some controls on your form, you would obviously like to get there values. For that purpose you need to add following code snippet in the click event of the cmdShowValues.
Well, this is a simple article about adding controls on a windows form; Nevertheless, you can do much more good work with the help of this article.