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" Me.Controls.Add(TextBox1) End Sub
You can see this code at work in Figure 5.7.
Related solution: |
Found on page: |
---|---|
196 |