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
先在窗体设计过程中手工增加一个picture1,index属性设定为0程序中要增加一个控件,就用:
Load Picture1(i)'i为
,1-n 最好顺序递增
Picture1(i).Visible = True '这句非常重要,否则新增的图片框看不到
Picture1(i).Move x, y, w, h '设定图片框的坐标和大小
可以啊,VB6我知道的有两种方法动态添加、删除控件,一种是用Controls,一种是用控件数组,不知道你用的哪种?用Controls:
dim frame1 as Frame
Set frame1 = Controls.Add("VB.Frame", "aa") ‘添加
frame1 .Visible = True
frame1.Width = 1000‘调整大小
frame1.Height = 1000
Controls.Remove aa’删除
用控件数组:
首先在窗体上添加一个Frame控件,命名为frameArray,Index属性为0
Load frameArray(1) '添加
frameArray(1).Width = 1000‘调整大小
frameArray(1).Height = 1000
frameArray(1).Visible = True
Unload frameArray(1) '删除
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)