Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi!

 

I have a form1 with a textbox1.

When i press Enter another textbox appears below.

As many textboxes as i want can appear.

When i click on button1 i want textbox1 to reset and all the other textboxes to disappear.

 

To do this i want to Reload form1 but i can't find the syntax (no Me.Reload found...! :mad: )

 

What is the syntax to reload a form by pressing on button1?

 

Thank you!

  • Leaders
Posted

you could do something like this :

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim box As Control
       For Each box In Controls
           If TypeOf box Is TextBox Then
               If Not box.Name = "TextBox1" Then
                   box.Text = ""
                   box.Visible = False
               End If
           End If
       Next
   End Sub

Posted
If you really want to get rid of the textboxes, you want TextBox.Dispose()

"It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve."

 

- Edgar Allan Poe, 1841

 

I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker.

 

- Helen Keller

Posted

I don't see how an object can "reload" itself.

 

You can either simulate that from the outside, by disposing and re-creating the whole form, or from inside the form, by manually implementing all necessary steps to a) clear all newly created controls and b) reset the data.

.nerd
  • *Experts*
Posted

You could have an arraylist to keep track of those newly created textboxes, and then when you want them to disappear go through the array and dispose them:

'Somewhere on top of your code
Dim boxes As New ArrayList
'then somewhere else in your keydown event...
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
   Dim txtBox As New TextBox
   'do some properties here...
   Me.Controls.Add(txtBox)
   boxes.Add(txtBox)
End Sub
'then somewhere else to dispose them....
Public Sub DestroyBoxes()
Dim x As Integer
For x = 0 to Boxes.Count - 1
    DirectCast(Boxes(x), TextBox).Dispose()
Next
End Sub

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...