展开全部
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
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
更多追问追答
追问
我写了一些代码,可是不能运行..您能帮我看一下吗?告诉我一个邮箱,我发给您吧
追答
pt98#sina#com
我上面的也运行不了?
展开全部
只能给你写一下,怎么装入 显示图片吧
显示图片用控件 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<i then
image.picture=loadpicture(paths(nowindex+1))
nowIndex =nowIndex +1
else
'是反到第一张还是其它自己决定
end if
显示图片用控件 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<i then
image.picture=loadpicture(paths(nowindex+1))
nowIndex =nowIndex +1
else
'是反到第一张还是其它自己决定
end if
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
简单,有偿索要。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询