Generating Controls by Textbox
Posted: Thu May 06, 2010 8:05 pm
I just found this on my harddrive while looking through project files pretty much what it does is you can have a textbox and enter a number and it will generate that number of controls. For this example we will be generating textboxes on the form.
What you need is:
1 button
1 textbox
1 flowlayout panel
For the declarations we are gonna put this:
you can use this for other controls too of course and this isnt much of a tutorial since I cant remember much about this project lol im finding alot of stuff while searching but here it is and have fun 8-)
What you need is:
1 button
1 textbox
1 flowlayout panel
For the declarations we are gonna put this:
Code: Select all
Now we are going to code for button1. Dim abox As TextBox
Dim count As Integer
Dim count2 As Integer
Code: Select all
Now when you enter a number in the textbox you can generate other textboxes, if you enter 5 then 5 textboxes will appear. Try
If Not textbox1.Text Is String.Empty Then
count2 = textbox1.Text
Else
Exit Sub
End If
For Me.count = 0 To count2 - 1
abox = New TextBox
abox.AutoSize = True
FlowLayoutPanel1.Controls.Add(abox)
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim intcount As Integer
If Not textbox1.Text Is String.Empty Then
count2 = textbox1.Text
Else
Exit Sub
End If
Try
For Me.count = 0 To count2 - 1
If Not textbox1.Text Is String.Empty Then
If FlowLayoutPanel1.Controls(count).Name = "abox_" & count & "_mycntrl" Then
If CInt(abox.Text) > 0 Then
intcount += CInt(FlowLayoutPanel1.Controls(count).Text)
End If
End If
End If
Next
Catch ex As Exception
End Try
textbox1.Clear()
