vb如何实现在程序中一次生成大批控件?

来源:百度知道 编辑:UC知道 时间:2024/05/10 04:50:57
比如我要实现运行程序时由用户输入生成shape控件的数量,指定位置,怎么做?
index属性具体怎么用?
答的好另加分,谢!
还有要生成像扫雷中的一大批commandbutton怎么办?

这是我以前编数据库时用到的。
定义
Private txtField() As TextBox
创建
ReDim txtField(0 To intSelectFieldCount - 1)

For I = 0 To intSelectFieldCount - 1
'创建新的控件
Set txtField(I) = Controls.Add("VB.TextBox", "TextBox_" & I)
'设置控件的容器、位置、宽、高
Set txtField(I).Container = fraEdit

txtField(I).Move 1600, 120 + I * 400, lngFieldWidth, 300

' 创建时,所有的控件都是不可见的
txtField(I).Visible = True
txtField(I).Enabled = True
Next I

引用
txtField(I).Text = "100"

PS:
你只要把定义改为 Dim Private () As Shape
创建新的控件 改为 Set sh(i) = Controls.Add("VB.Shape", "Shape_" & i)
用法如:sh(1).Visible = True

还有要生成像扫雷中的一大批commandbutton怎么办?