關于點擊pictureBox時?
'加載圖片后,pictureBox控件與文件路徑就沒有關聯了,只能在加載圖片時保存路徑,
'自定義函數同時加載圖片和保存路徑,假設這些pictureBox不是控件數組
Dim Names As New Collection '定義一個集合
Sub myLoadPicture(pic As PictureBox, FileName As String)
pic.Picture = LoadPicture(FileName) '加載圖片
On Error Resume Next
Names.Remove pic.Name
Names.Add FileName, pic.Name '保存路徑
End Sub
Sub SwapPicture(pic1 As PictureBox, pic2 As PictureBox)
Set SP = pic1.Picture
pic1.Picture = pic2.Picture
pic2.Picture = SP '交換PictureBox的圖片
On Error Resume Next
a = Names(pic1.Name)
b = Names(pic2.Name)
Names.Remove pic1.Name
Names.Remove pic2.Name
Names.Add b, pic1.Name
Names.Add a, pic2.Name '交換圖片路徑
End Sub
'調取圖片和獲取路徑
myLoadPicture Picture1, "01.bmp" '在Picture1中顯示圖片"01.bmp"
Names(Picture1.Name) '獲取Picture1中的圖片路徑
SwapPicture Picture1, Picture2 '交換Picture1和Picture2的圖片