用vb6.0做一个图片浏览(24张图),有“上一张”和“下一张”按钮来控制,急求~代码谢谢

窗体上显示单张图,及上一张。,下一张按钮。。。
2024-12-19 04:58:19
推荐回答(3个)
回答1:

Option Explicit
Dim temp() As String, defaultN As Long
Private Sub Command1_Click()
defaultN = defaultN - 1
If defaultN = 0 Then defaultN = UBound(temp)
Picture1.Picture = LoadPicture(temp(defaultN))
End Sub
Private Sub Command2_Click()
defaultN = defaultN + 1
If defaultN > UBound(temp) Then defaultN = 1
Picture1.Picture = LoadPicture(temp(defaultN))
End Sub
Function getfilename(pathname As String, temp) As Boolean
Dim f, n As Long
pathname = pathname & IIf(Right(pathname, 1) = "\", "", "\")
f = Dir(pathname, vbDirectory)
If Len(f) = 0 Then
Exit Function
End If
Do While f <> ""
If f <> "." And f <> ".." Then
If LCase(Right(pathname & f, 4)) = ".jpg" Then
n = n + 1
ReDim Preserve temp(1 To n)
temp(n) = pathname & f
End If
End If
f = Dir()
Loop
If n > 0 Then getfilename = True
End Function
Private Sub Form_Load()
If getfilename("d:\a", temp) Then '假设文件位置
Command1.Caption = "上一张"
Command2.Caption = "下一张"
defaultN = 1
Picture1.Picture = LoadPicture(temp(defaultN))
Else
MsgBox "无图片文件"
Unload Me
End If
End Sub

回答2:

只能给你写一下,怎么装入 显示图片吧
显示图片用控件 image 不要用 picture
装入图片为image .picture=loadpicture([图片路径])
.如果图片路径固定,名称有规律 真接生成路径就行了
如果没有规律 也不是在一个地方 ,那就加一个 应该是 dialog 的控件,这个要引用 (好久没有用Vb6了 你应该知道那个的,经常用到的
一个数组 保存路径
如果你的路径数组为 private paths() as string,l as integer
添加时就可以用
redim presave paths(i)
paths(i)=filedialog.filename
i=i+1
上一张 下一张 那就
申请一个记录当前编号的变量 private nowIndex as integer
下一张就是
if nowIndex +1 image.picture=loadpicture(paths(nowindex+1))
nowIndex =nowIndex +1
else
'是反到第一张还是其它自己决定
end if

回答3:

简单,有偿索要。