📄 thumbnailsform.vb
字号:
Imports System.IO
Public Class ThumbnailsForm
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents DrivesList As System.Windows.Forms.ComboBox
Friend WithEvents FoldersList As System.Windows.Forms.ListBox
'Required by the Windows Form Designer
Private components As System.ComponentModel.Container
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.FoldersList = New System.Windows.Forms.ListBox()
Me.DrivesList = New System.Windows.Forms.ComboBox()
Me.SuspendLayout()
'
'FoldersList
'
Me.FoldersList.Font = New System.Drawing.Font("Verdana", 9!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.FoldersList.ItemHeight = 14
Me.FoldersList.Location = New System.Drawing.Point(8, 36)
Me.FoldersList.Name = "FoldersList"
Me.FoldersList.Size = New System.Drawing.Size(216, 214)
Me.FoldersList.TabIndex = 1
'
'DrivesList
'
Me.DrivesList.DropDownWidth = 232
Me.DrivesList.Font = New System.Drawing.Font("Verdana", 9!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.DrivesList.Location = New System.Drawing.Point(8, 8)
Me.DrivesList.Name = "DrivesList"
Me.DrivesList.Size = New System.Drawing.Size(112, 22)
Me.DrivesList.TabIndex = 0
Me.DrivesList.Text = "ComboBox1"
'
'ThumbnailsForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.AutoScroll = True
Me.ClientSize = New System.Drawing.Size(616, 253)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.FoldersList, Me.DrivesList})
Me.Name = "ThumbnailsForm"
Me.Text = "ThumbNails Demo"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
ShowAllDrives()
DrivesList.SelectedIndex = 1
Me.Text = Directory.GetCurrentDirectory
End Sub
Sub ShowAllDrives()
Dim drives() As String
drives = Directory.GetLogicalDrives()
Dim aDrive As String
DrivesList.Items.Clear()
For Each aDrive In drives
DrivesList.Items.Add(aDrive)
Next
End Sub
Sub ShowFoldersInDrive(ByVal drive As String)
Dim folders() As String
Try
folders = Directory.GetDirectories(drive)
Catch exception As Exception
MsgBox(exception.Message)
Exit Sub
End Try
Dim fldr As String
FoldersList.Items.Clear()
Dim DI As DirectoryInfo
For Each fldr In folders
DI = New DirectoryInfo(fldr)
FoldersList.Items.Add(DI.Name)
Next
Directory.SetCurrentDirectory(drive)
Me.Text = Directory.GetCurrentDirectory
End Sub
Sub ShowFilesInFolder()
Dim file As String
Dim FI As FileInfo
Dim PBox As PictureBox, img As Image
Dim Left As Integer = 280
Dim Top As Integer = 40
Dim ctrl As Integer
For ctrl = Me.Controls.Count - 1 To 2 Step -1
Me.Controls.Remove(Me.Controls(ctrl))
Next
Me.Invalidate()
For Each file In Directory.GetFiles(Directory.GetCurrentDirectory)
FI = New FileInfo(file)
If FI.Extension = ".GIF" Or FI.Extension = ".JPG" Then
PBox = New PictureBox()
img = Image.FromFile(FI.FullName)
PBox.Image = _
img.GetThumbnailImage(64, 64, Nothing, Nothing)
If Left > 580 Then
Left = 280
Top = Top + 74
End If
PBox.Left = Left
PBox.Top = Top
PBox.Width = 64
PBox.Height = 64
PBox.Visible = True
PBox.Tag = FI.FullName
Me.Controls.Add(PBox)
AddHandler PBox.Click, _
New System.EventHandler(AddressOf OpenImage)
Left = Left + 74
End If
Next
End Sub
Sub OpenImage(ByVal sender As Object, ByVal e As System.EventArgs)
MsgBox("will open " & sender.tag)
Dim imgForm As New previewForm()
imgForm.PictureBox1.Image = Image.FromFile(sender.tag)
imgForm.Show()
End Sub
Private Sub DrivesList_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles DrivesList.SelectedIndexChanged
ShowFoldersInDrive(DrivesList.Text)
'dir = DrivesList.Text
End Sub
Private Sub FoldersList_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles FoldersList.SelectedIndexChanged
Dim DI As DirectoryInfo
Select Case FoldersList.Text
Case ""
MsgBox("Please select a folder to expand")
Exit Sub
Case ".."
Directory.SetCurrentDirectory("..")
Case Else
Directory.SetCurrentDirectory(Directory.GetCurrentDirectory & _
"\" & FoldersList.Text)
Me.Text = Directory.GetCurrentDirectory
End Select
Dim folders() As String
Dim selectedFolder As String = FoldersList.Text
folders = Directory.GetDirectories(Directory.GetCurrentDirectory)
FoldersList.Items.Clear()
If Directory.GetCurrentDirectory <> _
Directory.GetDirectoryRoot(selectedFolder) Then _
FoldersList.Items.Add("..")
Dim fldr As String
For Each fldr In folders
DI = New DirectoryInfo(fldr)
FoldersList.Items.Add(DI.Name)
Next
ShowFilesInFolder()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -