十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
Option Explicit
成都创新互联公司-专业网站定制、快速模板网站建设、高性价比长海网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式长海网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖长海地区。费用合理售后完善,十载实体公司更值得信赖。
Private WithEvents NewTextBox As TextBox
'通过使用WithEvents关键字声明一个对象变量为新的命令按钮
Private Sub Command1_Click()
If NewTextBox Is Nothing Then
Set NewTextBox = Controls.Add("VB.TextBox", "cmdNew", Form1)
NewTextBox.Move 200, 200
NewTextBox.Width = Form1.Width - 450
NewTextBox.Height = Form1.Height - 1400
NewTextBox.Visible = True
End If
End Sub
Private Sub Command2_Click()
If NewTextBox Is Nothing Then
Exit Sub
Else
Controls.Remove NewTextBox
Set NewTextBox = Nothing
End If
End Sub
Dim Str(20) As String '20数据元素
Dim Text(20) As TextBox
Dim n As Integer = 0
For Each i In Text
i = New TextBox '实例化
i.Location = New Point(50, n * 20)
Me.Controls.Add(i) '添加窗体
Dim Index As Integer = i.TabIndex '没index属性
Str(n) = Index
i.Text = Str(n) 'str数组值赋值给文本框
n += 1
Next
Private Sub b_click(sender As Object, e As EventArgs)
MsgBox(sender.name)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim b() As Button = {Button1, Button2, Button3}
For Each i In b
AddHandler i.Click, AddressOf b_click
Next
End Sub
我是VB.Net 2010,你看看能行不。
Public Class Form1
Private MyTextBoxArray As New ArrayList
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 0 To 8 '利用循环语句动态加入控件数组。
Dim FirstTextBox As New TextBox
'定义文本框对象
Me.Controls.Add(FirstTextBox)
'将一个文本框控件加入到Form上
MyTextBoxArray.Add(FirstTextBox)
'将文本框控件加入到例表集合中
MyTextBoxArray.Item(i).top = i * MyTextBoxArray.Item(i).height + 20 '修改新加入控件在Form上的位置
MyTextBoxArray.Item(i).left = 100
FirstTextBox.TabIndex = i
'修改新加入控件的TabIndex值
MyTextBoxArray.Item(i).text = "TextBox" i.ToString '修改默认文本。
Next
End Sub
End Class