'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
Dim i As Integer
Private Sub Picture1_Click()
Select Case i
Case 0
Me.Picture1.Picture = LoadPicture("0.bmp")
Case 1
Me.Picture1.Picture = LoadPicture("1.bmp")
Case 2
Me.Picture1.Picture = LoadPicture("2.bmp")
Case 3
Me.Picture1.Picture = LoadPicture("3.bmp")
End Select
i = i + 1
If i = 4 Then i = 0
Private Sub picoutput_Click(Index As Integer)
Dim i As Integer
m_ClickCount = 1
For i = 0 To 15
Select Case m_ClickCount
Case 1
Set picoutput(i).Picture = LoadPicture("C:\David 's bag\Item\P_On.bmp")
m_ClickCount = m_ClickCount + 1
Case 2
Set picoutput(i).Picture = LoadPicture("C:\David 's bag\Item\P_Off.bmp")
m_ClickCount = m_ClickCount + 1
Case Else
Set picoutput(i).Picture = LoadPicture("C:\David 's bag\Item\P_On.bmp")
m_ClickCount = 1
End Select
If m_ClickCount >= 2 Then m_ClickCount = 1
用个全局变量控制贝。 比如m_ClickCount
click事件就:
select case m_ClickCount
case 0
set picture1.picture=loadpicture("0.bmp")
case 1
set picture1.picture=loadpicture("1.bmp")
case 2
set picture1.picture=loadpicture("2.bmp")
...
case else
end select
如果要轮回,再加个 if m_ClickCount>=10 then m_ClickCount=0
Option Explicit
Dim FileIndex(N-1) as long '这个N由具体情况决定,可别照抄哦。
...
...
Sub picture1_click(index as integer)
FileIndex(index) = (Fileindex(index) +1) mod 16
'因为图像文件编号从0到15共16个,所以要MOD 16 。如果不是16个,楼主自己改数字
picuture1(index).picture = loadpicture(app.path & "\" & FileIndex(index) & ".bmp")
End Sub
Option exlpicit
Dim FileIndex as long
...
...
Sub picture1_click()
FileIndex = (Fileindex +1) mod 16
picuture1.picture = loadpicture(app.path & "\" & FileIndex & ".bmp")
End Sub
这样,当你按一次PICTURE就会自动载入下一幅图片,并且可以实现自动循环。
Private Sub picoutput_Click(Index As Integer)
Dim i As Integer
m_ClickCount = 1
Select Case m_ClickCount
Case 1
Set picoutput(i).Picture = LoadPicture("C:\David 's bag\Item\P_On.bmp")
m_ClickCount = m_ClickCount + 1
Case 2
Set picoutput(i).Picture = LoadPicture("C:\David 's bag\Item\P_Off.bmp")
m_ClickCount = m_ClickCount + 1
Case Else
Set picoutput(i).Picture = LoadPicture("C:\David 's bag\Item\P_On.bmp")
m_ClickCount = 1
End Select
If m_ClickCount >= 2 Then m_ClickCount = 1