VB动态添加控件的问题——TextBox文本框

2024年12月02日 11:11
有4个网友回答
网友(1):

Private Sub Command1_Click()
Dim a As TextBox
Dim i As Integer
For i = 0 To 9
Set a = Form1.Controls.Add("VB.TextBox", "Text" & i)
a.Visible = True
a.Move i * 500, i * 400, 1000, 300
a.BackColor = RGB(255, 255, 255)
a.Text = "Text" & i
Next
Lab.Caption = "动态添加控件成功"
End Sub

网友(2):

Private Sub Command1_Click()
Dim a As TextBox
Dim i As Integer
For i = 0 To 9
Set a = Form1.Controls.Add("VB.TextBox", "Text" & i)
a.Visible = True
a.Move i * 500, i * 400, 1000, 300
a.BackColor = RGB(255, 255, 255)
a.Text = "Text" & i
Next
MsgBox "动态添加控件成功"
End Sub

网友(3):

1. 首先,你是动态添加textbox文本框的,那么你Dim a As Label肯定类型不匹配,可以直接Dim a
2. textbox文本框没有Caption属性,只有text属性

修改这两处后,可以执行了

网友(4):

Dim a As textbox

a.text = "text" & i