⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 browser.vb

📁 还不错哦,有空看看,请多多指点.有什么不好的请与我联系,
💻 VB
字号:
Imports System.IO
Public Class Browser
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    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

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
    Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
    Friend WithEvents txtPath As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents picView As System.Windows.Forms.PictureBox
    Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
    Friend WithEvents cmnuSaveAs As System.Windows.Forms.MenuItem
    Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.MainMenu1 = New System.Windows.Forms.MainMenu
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        Me.MenuItem2 = New System.Windows.Forms.MenuItem
        Me.txtPath = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.StatusBar1 = New System.Windows.Forms.StatusBar
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.Splitter1 = New System.Windows.Forms.Splitter
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.picView = New System.Windows.Forms.PictureBox
        Me.ContextMenu1 = New System.Windows.Forms.ContextMenu
        Me.cmnuSaveAs = New System.Windows.Forms.MenuItem
        Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'MainMenu1
        '
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2})
        Me.MenuItem1.Text = "文件"
        '
        'MenuItem2
        '
        Me.MenuItem2.Index = 0
        Me.MenuItem2.Text = "退出"
        '
        'txtPath
        '
        Me.txtPath.Dock = System.Windows.Forms.DockStyle.Top
        Me.txtPath.Location = New System.Drawing.Point(0, 0)
        Me.txtPath.Name = "txtPath"
        Me.txtPath.Size = New System.Drawing.Size(536, 21)
        Me.txtPath.TabIndex = 0
        Me.txtPath.Text = ""
        '
        'Label1
        '
        Me.Label1.Dock = System.Windows.Forms.DockStyle.Top
        Me.Label1.Location = New System.Drawing.Point(0, 21)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(536, 11)
        Me.Label1.TabIndex = 1
        '
        'StatusBar1
        '
        Me.StatusBar1.Location = New System.Drawing.Point(0, 344)
        Me.StatusBar1.Name = "StatusBar1"
        Me.StatusBar1.Size = New System.Drawing.Size(536, 22)
        Me.StatusBar1.TabIndex = 2
        Me.StatusBar1.Text = "StatusBar1"
        '
        'ListBox1
        '
        Me.ListBox1.Dock = System.Windows.Forms.DockStyle.Left
        Me.ListBox1.ItemHeight = 12
        Me.ListBox1.Location = New System.Drawing.Point(0, 32)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(120, 304)
        Me.ListBox1.TabIndex = 3
        '
        'Splitter1
        '
        Me.Splitter1.Location = New System.Drawing.Point(120, 32)
        Me.Splitter1.Name = "Splitter1"
        Me.Splitter1.Size = New System.Drawing.Size(3, 312)
        Me.Splitter1.TabIndex = 4
        Me.Splitter1.TabStop = False
        '
        'Panel1
        '
        Me.Panel1.BackColor = System.Drawing.Color.Gray
        Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Panel1.Controls.Add(Me.picView)
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.Panel1.Location = New System.Drawing.Point(123, 32)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(413, 312)
        Me.Panel1.TabIndex = 5
        '
        'picView
        '
        Me.picView.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.picView.BackColor = System.Drawing.Color.Transparent
        Me.picView.ContextMenu = Me.ContextMenu1
        Me.picView.Location = New System.Drawing.Point(8, 8)
        Me.picView.Name = "picView"
        Me.picView.Size = New System.Drawing.Size(400, 296)
        Me.picView.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage
        Me.picView.TabIndex = 0
        Me.picView.TabStop = False
        '
        'ContextMenu1
        '
        Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.cmnuSaveAs})
        '
        'cmnuSaveAs
        '
        Me.cmnuSaveAs.Index = 0
        Me.cmnuSaveAs.Text = "另存为"
        '
        'Browser
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(536, 366)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.Splitter1)
        Me.Controls.Add(Me.ListBox1)
        Me.Controls.Add(Me.StatusBar1)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.txtPath)
        Me.Menu = Me.MainMenu1
        Me.Name = "Browser"
        Me.Text = "my ACD See 1.0"
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim dir As Directory '目录对象
    Dim crtDir As String    '当前目录
    Dim crtFile As String   '当前文件
    Dim initDir As String = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)      '默认文件夹为“图片珍藏”


    Private Sub LoadPic(ByVal picDir As String)
        If Not dir.Exists(picDir) Then Exit Sub
        Me.ListBox1.Items.Clear()
        Me.ListBox1.Items.Add("..")

        '将文件夹中的子文件夹加载到列表控件中。
        Dim i As Integer
        Dim sDirs() As String
        sDirs = dir.GetDirectories(picDir)
        txtPath.Text = picDir

        While i < sDirs.Length
            ListBox1.Items.Add(GetEndDir(sDirs(i)).Trim & "\")
            i += 1
        End While

        '将文件夹中的图片加载到列表控件中。
        Dim fName As String
        Dim sFiles() As String
        sFiles = dir.GetFiles(picDir, "*.jpg")
        i = 0
        While i < sFiles.Length
            fName = System.IO.Path.GetFileNameWithoutExtension(sFiles(i))
            ListBox1.Items.Add(fName)
            i += 1
        End While

    End Sub

    Private Function GetEndDir(ByVal FullPath As String) As String
        Dim i As Integer = InStrRev(FullPath, "\")
        GetEndDir = Mid$(FullPath, i + 1)
    End Function

    Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        If ListBox1.SelectedIndex = 0 Then
            GotoParent()
            loadPic(crtDir)
        Else
            Dim str As String
            str = ListBox1.SelectedItem
            If InStrRev(str, "\") > 0 Then
                GotoDir(str)
            End If
        End If
    End Sub

    '回到上一级目录。
    Private Sub GotoParent()
        crtDir = dir.GetParent(crtDir).ToString
        If InStrRev(crtDir, "\") = crtDir.Length Then
            crtDir = Mid$(crtDir, 1, crtDir.Length - 1)
        End If
    End Sub

    '进到下一级子目录
    Private Sub GotoDir(ByVal DirName As String)
        crtDir = crtDir & "\" & DirName
        If InStrRev(crtDir, "\") = crtDir.Length Then
            crtDir = Mid$(crtDir, 1, crtDir.Length - 1)
        End If
        loadPic(crtDir)
    End Sub

    '预览图片
    Private Sub ViewPic(ByVal i As Integer)
        crtFile = crtDir & "\" & ListBox1.SelectedItem & ".jpg"
        picView.Image = Image.FromFile(crtFile)
    End Sub

    'click event
    Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.Click
        If ListBox1.SelectedIndex > 0 Then      '不包含第一项,因为第一项是上一级文件夹。
            Dim str As String
            str = ListBox1.SelectedItem
            If InStrRev(str, "\") = 0 Then       '没包含反斜框,是图片而不是文件夹。
                ViewPic(ListBox1.SelectedIndex)
            End If
        End If
    End Sub

    Private Sub cmnuSaveAs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmnuSaveAs.Click
        Dim ff As File
        Dim destFileName As String
        SaveFileDialog1.Filter = "压缩格式图像文件(*.jpg)|*.jpg"
        Me.SaveFileDialog1.ShowDialog(Me)
        If SaveFileDialog1.FileName = "" Then Exit Sub
        ff.Copy(crtFile, SaveFileDialog1.FileName)
        ff = Nothing
    End Sub

    Private Sub Browser_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        crtDir = initDir
        LoadPic(initDir)
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -