Professional Documents
Culture Documents
Dpbo Sandi Rigo Nugraha
Dpbo Sandi Rigo Nugraha
Dpbo Sandi Rigo Nugraha
- Stack Overflow
x Dismiss
Sign up
How to create a form with a button add_subjects which adds one textbox and a corresponding label on each click, 3 buttons - Add, Edit and
Delete , for each textbox created during runtime in VB . Once each texbox's corresponding Add _button is clicked, it passes textbox's
value to the label.
vb.net winforms
1 why dont you use datagrid and edit everthing there? DevelopmentIsMyPassion Jan 8 '14 at 9:30
3 Answers
A control like a textbox is just an object of the class Textbox. In order for the form to display
this object it needs to be added to the form's Controls property. To create a new textbox all you
need to do is
If you want your control to be able to respond to events you need to add an event handler for
the event you want to the control. This handler refers the event to a method of your choice.
Sub CreateTB
Dim NewTB as New Textbox
newTB = New Textbox
newTB.Name = "tbNew"
AddHandler newTB.TextChanged, AddressOf HandleTextChanged
Me.Controls.Add(newTB)
End Sub
You should make sure that the names are unique if you are creating the controls or you might
run into trouble.
You can also store your created controls in an array or list as a global variable. That way you
can easily access them afterwards.
https://stackoverflow.com/questions/20991539/how-to-add-textboxes-labels-and-buttons-dynamically-at-runtime-in-vb 1/3
8/7/2017 vb.net - How to add textboxes, labels and buttons dynamically at runtime in VB? - Stack Overflow
So we make all controls, dynamically make names, change positions, add handlers and add
controls to form.
Here we find Label And TextBox using sender's number(sender.Name.Substring(9) will remove
AddButton and leave number) and change Label.Text to TextBox.Text.
Is it possible to track each of these dynamically created labels and their values, so that I can store those
labels values as a table fields in a database using SQL embedded in a button_save_subjects event?
user3172488 Jan 8 '14 at 14:31
I added code to get all values,but I don't know SQL so you'll have to insert values in database. srka Jan 8
'14 at 20:41
https://stackoverflow.com/questions/20991539/how-to-add-textboxes-labels-and-buttons-dynamically-at-runtime-in-vb 2/3
8/7/2017 vb.net - How to add textboxes, labels and buttons dynamically at runtime in VB? - Stack Overflow
Create Dynamic Label]
Refer Here
Source
https://stackoverflow.com/questions/20991539/how-to-add-textboxes-labels-and-buttons-dynamically-at-runtime-in-vb 3/3