On Error GoTo balle1
File1.ListIndex = JB
If Right(File1.Path, 1) <> "\" Then
nisse.Caption = File1.Path & "\" & File1.FileName
Else
nisse.Caption = File1.Path & File1.FileName
End If
Frame1.Caption = File1.FileName
Image1.Picture = LoadPicture(nisse.Caption)
On Error GoTo balle2
JB = JB + 1
File1.ListIndex = JB
If Right(File1.Path, 1) <> "\" Then
nisse.Caption = File1.Path & "\" & File1.FileName
Else
nisse.Caption = File1.Path & File1.FileName
End If
Frame2.Caption = File1.FileName
Image2.Picture = LoadPicture(nisse.Caption)
On Error GoTo balle3
JB = JB + 1
File1.ListIndex = JB
If Right(File1.Path, 1) <> "\" Then
nisse.Caption = File1.Path & "\" & File1.FileName
Else
nisse.Caption = File1.Path & File1.FileName
End If
Frame3.Caption = File1.FileName
Image3.Picture = LoadPicture(nisse.Caption)
On Error GoTo balle4
JB = JB + 1
File1.ListIndex = JB
If Right(File1.Path, 1) <> "\" Then
nisse.Caption = File1.Path & "\" & File1.FileName
Else
nisse.Caption = File1.Path & File1.FileName
End If
Frame4.Caption = File1.FileName
Image4.Picture = LoadPicture(nisse.Caption)
On Error GoTo balle5
JB = JB + 1
File1.ListIndex = JB
If Right(File1.Path, 1) <> "\" Then
nisse.Caption = File1.Path & "\" & File1.FileName
Else
nisse.Caption = File1.Path & File1.FileName
End If
Frame5.Caption = File1.FileName
Image5.Picture = LoadPicture(nisse.Caption)
On Error GoTo balle6
JB = JB + 1
File1.ListIndex = JB
If Right(File1.Path, 1) <> "\" Then
nisse.Caption = File1.Path & "\" & File1.FileName
Else
nisse.Caption = File1.Path & File1.FileName
End If
Frame6.Caption = File1.FileName
Image6.Picture = LoadPicture(nisse.Caption)
On Error GoTo balle7
JB = JB + 1
File1.ListIndex = JB
If Right(File1.Path, 1) <> "\" Then
nisse.Caption = File1.Path & "\" & File1.FileName
Else
nisse.Caption = File1.Path & File1.FileName
End If
Frame7.Caption = File1.FileName
Image7.Picture = LoadPicture(nisse.Caption)
On Error GoTo balle8
JB = JB + 1
File1.ListIndex = JB
If Right(File1.Path, 1) <> "\" Then
nisse.Caption = File1.Path & "\" & File1.FileName
Else
nisse.Caption = File1.Path & File1.FileName
End If
Frame8.Caption = File1.FileName
Image8.Picture = LoadPicture(nisse.Caption)
Exit Sub
balle1:
Frame1.Visible = False
Resume Next
Exit Sub
balle2:
Frame2.Visible = False
Resume Next
Exit Sub
balle3:
Frame3.Visible = False
Resume Next
Exit Sub
balle4:
Frame4.Visible = False
Resume Next
Exit Sub
balle5:
Frame5.Visible = False
Resume Next
Exit Sub
balle6:
Frame6.Visible = False
Resume Next
Exit Sub
balle7:
Frame7.Visible = False
Resume Next
Exit Sub
balle8:
Frame8.Visible = False
Resume Next
Exit Sub
End Sub
Private Sub Command1_Click()
If JB > 14 Then
JB = JB - 15
Call uppd
End If
End Sub
Private Sub Command2_Click()
If Frame1.Visible = False And Frame2.Visible = False And Frame3.Visible = False And Frame4.Visible = False And Frame5.Visible = False And Frame6.Visible = False And Frame7.Visible = False And Frame8.Visible = False Then
Command1.Value = True
Exit Sub
End If
JB = JB + 1
Call uppd
End Sub
Private Sub Command3_Click()
JB = 0
Call uppd
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
On Error GoTo ju
Dir1.Path = Drive1.Drive
Exit Sub
ju:
MsgBox "Drive not ready!"
Exit Sub
End Sub
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()
MSFlexGrid1.Move 0, 0, Me.Width, Me.Height
loadpics App.Path
MSFlexGrid1.Rows = mypics.Count + 1
MSFlexGrid1.Cols = 2
MSFlexGrid1.FixedCols = 0
MSFlexGrid1.FixedRows = 0
MSFlexGrid1.ColWidth(0) = 2000
MSFlexGrid1.ColWidth(1) = 5000
Dim i As Integer
For i = 1 To mypics.Count
MSFlexGrid1.RowHeight(i) = 1000
addpicture i, mypics(i)
Next
End Sub
假设用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