我有两组图片保存在两个文件夹中。我希望程序在全屏窗体的中心随机显示这些图片。我试图用visual basic做到这一点。
Private Sub VScroll1_Change()
End Sub
Private Sub Command1_Click()
Form2.Show
Form1.Hide
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
End Sub
Private Sub Timer1_Timer()
If Interval > 0 Then
Timer1.Enabled = True
Else
Timer1.Enabled = False
Form2.Hide
End
End If
End Sub
答案 0 :(得分:0)
如果使用图像控件显示图片,并且图像控件名称为“Image1”,则每次更改图片时,您都可以使用以下在中心重新定位图像。
Image1.Left = (Me.ScaleWidth - Image1.Width) / 2
Image1.Top = (Me.ScaleHeight - Image1.Height) / 2
添加以下内容:
您必须在表单中放置一个FileListBox控件并将其命名为f
Dim folder As String
Dim n As Integer
Private Sub Timer1_Timer()
n = Rnd() * f.ListCount
Image1.Picture = LoadPicture(folder & "\" & f.List(n))
Image1.Left = (Me.ScaleWidth - Image1.Width) / 2
Image1.Top = (Me.ScaleHeight - Image1.Height) / 2
End Sub
Private Sub Form_Load()
folder = "D:\VLTR"
f.Visible = False
f.Pattern = "*.jpg"
f.Path = folder
End Sub