JavaScript Editor
JavaScript Debugger|
| ||
You can add or remove controls to your application at run time-all you need to do is to use the form's Controls collection 's Add or Remove methods. We'll see collections later in the book; they let you operate on a number of objects at once, as with the Add and Remove methods.
Here's an example (AddControls on the CD-ROM) that adds a new text box at run time-all you have to do is to create a new text box in code, give it a size and location, set its text, and use the Add method when the user clicks a button:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim NewTextBox As New TextBox()
NewTextBox.Size = New Size(100, 20)
NewTextBox.Location = New Point(100, 100)
NewTextBox.Text = "Hello from Visual Basic"
Me.Controls.Add(NewTextBox)
End Sub
You can see the results in Figure 4.22; when the user clicks a button, a new text box appears in the form.
|
Related solutions: |
Found on page: |
|---|---|
|
244 |
|
|
284 |
|
| ||
Free JavaScript Editor
JavaScript Editor