控件名 | 控件类型 | 标题 | 说明 |
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 |