Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

           Dim txtNew As TextBox = New System.Windows.Forms.TextBox()
           txtNew.Location = New System.Drawing.Point(25 + f, 248)
           txtNew.MaxLength = 1
           txtNew.Name = "txt" & letter
           txtNew.ReadOnly = True
           txtNew.Size = New System.Drawing.Size(16, 20)
           txtNew.Text = letter
           txtNew.TextAlign = HorizontalAlignment.Center

           Controls.Add(txtNew)

 

This is a sample of my code, its from a little game. You have to guess a word, everytime when u input a wrong letter, its dynamicly generates a txtbox with the wrong letter. Now when u guessed the word or it's game over the dynamicly generated textboxes need to be cleared/unloaded. Not just empty but invisible, so you can start another game.

Can somebody help me with it.

  • Moderators
Posted

You can iterate the controls..

       Dim c As Control
       For Each c In Me.Controls
           If TypeOf c Is TextBox Then
               c.Dispose()
           End If
       Next

 

I suggest placing the textboxes in a Panel so you can simply loop it instead the entire form.

       For Each c In Panel1.Controls

Visit...Bassic Software
Posted

tnx, alot for replying.

I used this for a solution.

 

               Static n
               Dim s As Integer
               n = Controls.GetChildIndex(txtNew)
               For s = 0 To 9
                   Controls.RemoveAt(n - s)
               Next s

 

But i need to use you're solution in the future because this time i knew s = 0 to 9, and next time it might be variable.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...