控件名 | 控件類型 | 標題 | 說明 |
Command1(1) | CommandButton | 上一頁 | 預覽上一頁圖片 |
Command1(0) | CommandButton | 下一頁 | 預覽下一頁圖片 |
Picture1 | PictureBox | 用來裝入預覽控件組的容器控件 | |
Image1(0) | Image | 顯示圖片控件 | |
Drive1 | DriveListBox | 顯示當前系統的磁盤列表 | |
Dir1 | DirListBox | 顯示當前磁盤的目錄列表 | |
File1 | FileListBox | 顯示當前目錄的圖片格式文件列表 |
Private Sub Dir1_Change() File1.Path = Dir1.Path End Sub Private Sub Drive1_Change() Dir1.Path = Drive1.Drive Call InitShowPic End Sub Private Sub File1_PathChange() ‘當文件列表發生變化時重新顯示圖片 Call InitShowPic End Sub |
Private Sub Form_Load() Dim i, j As Integer For i = 1 To 24 ‘動態創建24個Image控件 Load Image1(i) ‘動態創建Image控件 Image1(i).Visible = True ‘顯示此控件 Next Drive1.Drive = "c:" ‘默認驅動器為C: Dir1.Path = "c:\" Picture1.DrawWidth = 3 For i = 1 To 4 ‘在Picture畫線將Image控件組以5×5排列 Picture1.Line (0, i * (Picture1.Height \ 5) - 30)-(Picture1.Width, i * (Picture1.Height \ 5) - 30), &H80000003 Picture1.Line (i * (Picture1.Width \ 5) - 30, 0)-(i * (Picture1.Width \ 5) - 30, Picture1.Height), &H80000003 Next For i = 0 To 4 For j = 0 To 4 Image1(i * 5 + j).Left = j * (Picture1.Width \ 5) + 50 Image1(i * 5 + j).Top = i * (Picture1.Height \ 5) + 50 Next Next currindex = -1 ‘當前選擇圖片的索引為-1表示沒有選擇圖片 End Sub Private Sub InitShowPic() ‘顯示當前目錄的第一頁圖片(1到25) Dim i As Integer For i = 0 To 24 ‘所有Image控件不顯示圖片 Image1(i).Picture = LoadPicture("") Image1(i).ToolTipText = "" Next If File1.ListCount = 0 Then ‘如果當前目錄沒有圖片 StatusBar1.Panels(1).Text = "" StatusBar1.Panels(2).Text = "" StatusBar1.Panels(3).Text = "" StatusBar1.Panels(4).Text = "" StatusBar1.Panels(4).Visible = False If currindex <> -1 Then ‘如果選擇了圖片,則顯示此圖片的Image控件的邊框風格改為平板風格 Image1(currindex).Appearance = 0 End If currpage = 1: currindex = -1 ‘當前選擇的頁號為1并不選擇圖片 Exit Sub End If currpage = 1: currindex = -1 ‘如果當前目錄有圖片,則將頁號賦值為1并不選擇圖片 Call DisplayPicPage(currpage) ‘調用自定義函數顯示指定頁號的圖片 End Sub Private Sub DisplayPicPage(page As Integer) ‘顯示指定頁的圖片 Dim i As Integer Dim usetime As Long On Error Resume Next usetime = GetTickCount If (File1.ListCount - (25 * (page - 1)) < 25) And (File1.ListCount - (25 * (page - 1)) > 0) Then For i = 0 To File1.ListCount Mod 25 - 1 Image1(i).Picture = LoadPicture(Dir1.Path + "\" + File1.List((page - 1) * 25 + i)) Image1(i).ToolTipText = File1.List((page - 1) * 25 + i) Next For i = File1.ListCount Mod 25 To 24 Image1(i).Picture = LoadPicture("") Image1(i).ToolTipText = "" Next StatusBar1.Panels(1).Text = "圖片:" & File1.ListCount & "(張)" + Space(5) + "當前第" & (currpage - 1) * 25 + 1 & "-" & (currpage - 1) * 25 + File1.ListCount Mod 25 & "張" Else For i = 0 To 24 Image1(i).Picture = LoadPicture(Dir1.Path + "\" + File1.List((page - 1) * 25 + i)) Image1(i).ToolTipText = File1.List((page - 1) * 25 + i) Next StatusBar1.Panels(1).Text = "圖片:" & File1.ListCount & "(張)" + Space(5) + "當前第" & (currpage - 1) * 25 + 1 & "-" & currpage * 25 & "張" End If StatusBar1.Panels(4).Text = "用時:" & GetTickCount - usetime & "(ms)" StatusBar1.Panels(4).Visible = True End Sub ‘點擊【上一頁】,【下一頁】按鈕事件 Private Sub Command1_Click(Index As Integer) File1.Refresh If File1.ListCount = 0 Then Exit Sub Select Case Index Case 0 If currpage = (File1.ListCount \ 25 + 1) Then Exit Sub currpage = currpage + 1 Call DisplayPicPage(currpage) Case 1 If currpage = 1 Then Exit Sub currpage = currpage - 1 Call DisplayPicPage(currpage) Case 2 If currindex <> -1 Then Image1(currindex).Appearance = 0 End If Call InitShowPic End Select End Sub |
Private Sub Form_Unload(Cancel As Integer) Dim i As Integer For i = 1 To 24 Unload Image1(i) Next End Sub |
![]() |
原文轉自:http://www.anti-gravitydesign.com