Generating Controls by Textbox

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
2 posts Page 1 of 1
Contributors
User avatar
jeezy09
VIP - Donator
VIP - Donator
Posts: 25
Joined: Wed Mar 31, 2010 1:51 am

Generating Controls by Textbox
jeezy09
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:
Code: Select all
    Dim abox As TextBox
    Dim count As Integer
    Dim count2 As Integer
Now we are going to code for button1.
Code: Select all
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()
Now when you enter a number in the textbox you can generate other textboxes, if you enter 5 then 5 textboxes will appear. :D 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-)
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1892
Joined: Wed Dec 16, 2009 9:56 pm

not bad
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
2 posts Page 1 of 1
Return to “Tutorials”