VB 动态添加textbox控件,让添加出来的控件触发Change
PrivateSubForm_Load()b=1EndSub============================================PrivateSubC...
Private Sub Form_Load()b = 1End Sub============================================Private Sub Command1_Click()Dim a As TextBox, b As Longb = b + 1Set a = Form1.Controls.Add("VB.TextBox", "Text" & b)a.Visible = Truea.BackColor = RGB(255, 255, 255)a.Text = "HJonny"a.BorderStyle = 0a.Move 0, 0, 2155, 255End Sub ====================================================这代码点击一下按钮就创建一个TextBox控件,我想让添加出来的能触发Change事件,就像这样:Private Sub Text1_Change()Label1.Caption = Text1.TextEnd Sub应该怎么实现呢?
展开
展开全部
你要这样,添加1个文本框Text1,然后设置它的 Index 属性为0
用下面代码:
Option Explicit
Dim a As TextBox, b As Long
Private Sub Form_Load()
b = 1
End Sub
Private Sub Command1_Click()
b = b + 1
Load Text1(b)
Text1(b).BackColor = RGB(255, 255, 255)
Text1(b).Text = "HJonny"
Text1(b).BorderStyle = 0
Text1(b).Move 0, 0, 2155, 255
Text1(b).Visible = True
End Sub
Private Sub Text1_Change(Index As Integer)
Label1.Caption = Text1(Index).Text
End Sub
还有问题要解决,你这个按钮1,可以不断添加文本框的,要适当修改代码.
用下面代码:
Option Explicit
Dim a As TextBox, b As Long
Private Sub Form_Load()
b = 1
End Sub
Private Sub Command1_Click()
b = b + 1
Load Text1(b)
Text1(b).BackColor = RGB(255, 255, 255)
Text1(b).Text = "HJonny"
Text1(b).BorderStyle = 0
Text1(b).Move 0, 0, 2155, 255
Text1(b).Visible = True
End Sub
Private Sub Text1_Change(Index As Integer)
Label1.Caption = Text1(Index).Text
End Sub
还有问题要解决,你这个按钮1,可以不断添加文本框的,要适当修改代码.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询