比如说添加一个文本框:
Dim t As TextBoxSet t = Controls.Add("VB.TextBox", "t1")
t.Move 300, 150, 3000, 2400
t.Visible = True
VB.TextBox 是文本框的类名,其他控件也有对应的类名,你可以自己去查。比如按钮就是 VB.CommandButton 。另外,代码建立的控件其Visible属性默认是False的(也就是不显示),要改为True才行。
首先添加一个窗体,在这个窗体上加一个文本框的控件,在这个文本框的单击事件中写如下的程序:
Dim num, sum, it(1), n, t, h
Private Sub Form_Click()
File1.Refresh
sum = 0
List1.Clear
For i = 0 To File1.ListCount - 1
t = Split(File1.List(i), ".")(UBound(Split(File1.List(i), ".")))
If LCase(t) = LCase("jpg") Or LCase(t) = LCase("bmp") Or LCase(t) = LCase("gif") Then List1.AddItem File1.List(i): sum = sum + 1
Next
h = Rnds(sum)
Print h
Image1.Picture = LoadPicture(List1.List(h))
End Sub
Private Sub Form_Load()
File1.Visible = 0
List1.Visible = 0
num = -1
End Sub
Function Rnds(ByVal Value)
re:
DoEvents
Randomize
n = Fix(Rnd * Value)
If num = 1 Then num = -1
num = num + 1
it(num) = n
If it(0) = it(1) Then GoTo re
Rnds = n
End Function
'添加image1、file1、list1控件各一个
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)