在一个IMAGE上切换显示某文件夹下所有图片文件
在一个IMAGE上切换显示某文件夹下所有图片文件:
'add an imagebox to form1,Then add the following codes:
Dim i As Integer, mypics As New Collection
Sub loadpics(ByVal mydir As String)
Set mypics = Nothing
mydir = mydir & IIf(Right(mydir, 1) = "\", "", "\")
Dim temp As String, ext As String
temp = Dir(mydir)
Do While Not temp = ""
ext = Mid(temp, InStr(temp, ".") + 1)
If ext = "bmp" Or ext = "gif" Or ext = "jpg" Or ext = "jpeg" Then mypics.Add mydir & temp
temp = Dir
Loop
End Sub
Private Sub Form_Load()
i = 0
loadpics "C:\My Documents\My Pictures"
Image1.Move 0, 0, Me.Width, Me.Height
Image1.Stretch = True
End Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then i = IIf(i = mypics.Count, 1, i + 1)
If Button = 2 Then i = IIf(i = 1, mypics.Count, i - 1)
Image1.Picture = LoadPicture(mypics(i))
Me.Caption = mypics(i)
End Sub
浙公网安备 33010602011771号