JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating a Text Box in Code

You also can create text boxes in code. Here's an example—CreateTextBox on the CD-ROM—that creates a text box when you click a button. In this case, I'm calling the TextBox class's constructor (TextBox() in the code below—as discussed in Chapter 2, a constructor is a special method you call to create an object from a class) to create a new text box, then positioning it and adding it to the form's Controls collection, as we did in Chapter 4:

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    Dim TextBox1 As New TextBox()
    TextBox1.Size = New Size(150, 20)
    TextBox1.Location = New Point(80, 20)
    TextBox1.Text = "Hello from Visual Basic"
End Sub

You can see this code at work in Figure 5.7.

Figure 5.7: Creating a text box from code.

Related solution:

Found on page:

Adding and Removing Controls at Run Time


Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor