高分寻求如何预览当前目录下面的所有图片?

hengj2008 2005-11-09 09:40:34
我只知道预览一副图片的方法,有人告诉我如何预览多幅图片?
前提是假设此目录下图片的多少未知。用picturebox或者image都可以。
有谁能提供一下代码,多谢拉!
...全文
242 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
fishmans 2005-11-10
  • 打赏
  • 举报
回复
'直接在一个picture上贴
dim pic as stdpicture
set pic=loadpicture("d:\d.bmp")
picture1.paintpicture pic,x,y,width1,height1

'可加循环
不知道哪个占资料大,呵呵
hengj2008 2005-11-10
  • 打赏
  • 举报
回复
可能是我表述不清楚
你们跟我说的是在一个image里面看多个图片。
我要的效果是类似于ACDSEE的点击一个目录,下面可以列出所有的图片的预览图。而不是以覆盖样式展示的一幅图。

哪位知道怎么做?谢谢啦
chen2839846 2005-11-10
  • 打赏
  • 举报
回复
啊 错了是三个按钮 一个前翻一个后翻 一个显示图片
chen2839846 2005-11-10
  • 打赏
  • 举报
回复
在窗体上放8个IMAGE 一个DIRLISTBOX 一个按钮就可以了
chen2839846 2005-11-10
  • 打赏
  • 举报
回复
Dim JB As Integer

Sub uppd()

Frame1.Visible = True
Frame2.Visible = True
Frame3.Visible = True
Frame4.Visible = True
Frame5.Visible = True
Frame6.Visible = True
Frame7.Visible = True
Frame8.Visible = True


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


northwolves 2005-11-10
  • 打赏
  • 举报
回复
可以用PICTUREBOX 控件数组或MSFLEXGRID 来实现,效率不高,仅供参考:

Dim mypics As New Collection


Sub addpicture(ByVal row As Integer, ByVal picpath As String)
Dim pic1 As PictureBox, pic2 As PictureBox

MSFlexGrid1.row = row
MSFlexGrid1.col = 0
Set pic1 = Controls.Add("vb.picturebox", "pic1", Me)
Set pic2 = Controls.Add("vb.picturebox", "pic2", Me)
pic1.Visible = False
pic2.Visible = False
pic2.AutoRedraw = True
pic1.AutoSize = True
pic2.Move 0, 0, MSFlexGrid1.CellWidth * 1.1, MSFlexGrid1.CellHeight * 1.1
pic1.Picture = LoadPicture(picpath)
pic2.PaintPicture pic1, 0, 0, MSFlexGrid1.CellWidth, MSFlexGrid1.CellHeight, 0, 0, pic1.Width, pic1.Height
SavePicture pic2.Image, "c:\temp.bmp"
Set MSFlexGrid1.CellPicture = LoadPicture("c:\temp.bmp")
MSFlexGrid1.TextMatrix(row, 1) = picpath
Controls.Remove pic1
Controls.Remove pic2
Kill "c:\temp.bmp"
End Sub



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()
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
northwolves 2005-11-09
  • 打赏
  • 举报
回复
假设用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

在IMAGE上单击左键或右可实现向后翻页或向前翻页

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧