如果要以编程方式创建新文本框,这可能有助于您:
Dim TextBox1 As New TextBox
With TextBox1
.Location = New Point(10, 10)
.Name = "TextBox1"
.Text = " "
.Visible = True
End With
AddHandler TextBox1.Click, AddressOf TextBox1_Click
Me.Controls.Add(TextBox1)
.Click
事件,我们必须声明处理它的函数:
Private Sub TextBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox("You clicked Me!")
End Sub
例如,如果窗体上有另一个文本框
TextBox1
我们可以使用它在orther中的位置创建一个新的文本框,如下所示:
Dim newTextBox As New TextBox
With newTextBox
.Location = New Point(TextBox1.Location.X, TextBox1.Location.Y + newTextBox.Height + 10)
.Name = "newTextBox"
.Visible = True
End With
AddHandler newTextBox.Click, AddressOf newTextBox_Click
Me.Controls.Add(newTextBox)
评论:
记住重命名处理
。单击
例如:
AddHandler newTextBox.Click, AddressOf newTextBox_Click
和
Private Sub newTextBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox("You clicked Me!")
End Sub
events
可以在vb.net中处理。
TextBox.Click