📄 form1.vb
字号:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim FileIndex, BmpFilePath, BmpFileName As String
#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
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents FileListBox1 As Microsoft.VisualBasic.Compatibility.VB6.FileListBox
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button2 = New System.Windows.Forms.Button
Me.Button1 = New System.Windows.Forms.Button
Me.FileListBox1 = New Microsoft.VisualBasic.Compatibility.VB6.FileListBox
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.Button3 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(160, 232)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(56, 23)
Me.Button2.TabIndex = 1
Me.Button2.Text = "上一张"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(80, 232)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(56, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "打开"
'
'FileListBox1
'
Me.FileListBox1.Location = New System.Drawing.Point(40, 40)
Me.FileListBox1.Name = "FileListBox1"
Me.FileListBox1.Pattern = "*.*"
Me.FileListBox1.Size = New System.Drawing.Size(120, 88)
Me.FileListBox1.TabIndex = 3
Me.FileListBox1.Visible = False
'
'ListBox1
'
Me.ListBox1.ItemHeight = 12
Me.ListBox1.Location = New System.Drawing.Point(184, 40)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(120, 88)
Me.ListBox1.TabIndex = 2
Me.ListBox1.Visible = False
'
'PictureBox1
'
Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.PictureBox1.Location = New System.Drawing.Point(20, 20)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(330, 200)
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(240, 232)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(56, 23)
Me.Button3.TabIndex = 1
Me.Button3.Text = "下一张"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(372, 273)
Me.Controls.Add(Me.FileListBox1)
Me.Controls.Add(Me.ListBox1)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.PictureBox1)
Me.Name = "Form1"
Me.Text = "浏览多张图片"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer, ilen As Integer
OpenFileDialog1.DefaultExt = "BMP文件(*.BMP)|*.BMP"
OpenFileDialog1.Filter = "BMP文件(*.BMP)|*.BMP|JPG文件(*.jpg)|*.jpg|ICO文件(*.ico)|*.ico|GIF文件(*.gif)|*.gif"
OpenFileDialog1.ShowDialog() '打开文件
ilen = Len(OpenFileDialog1.FileName)
For i = 1 To ilen
If Mid(OpenFileDialog1.FileName, ilen - i + 1, 1) = "\" Then
BmpFilePath = Mid(OpenFileDialog1.FileName, 1, ilen - i + 1)
BmpFileName = Mid(OpenFileDialog1.FileName, ilen - i + 2, ilen - i)
Exit For
End If
System.Windows.Forms.Application.DoEvents()
Next i
FindFiles() '列出该目录下的所有图像文件
ShowBmp() '显示图片
If FileIndex = 0 Then
Button1.Enabled = False
Else
Button1.Enabled = True
End If
If FileIndex = ListBox1.Items.Count - 1 Then
Button2.Enabled = False
Else
Button2.Enabled = True
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If FileIndex = 0 Then '上一张
Button1.Enabled = False
Else
FileIndex = FileIndex - 1
Button2.Enabled = True
ShowBmp()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If FileIndex = ListBox1.Items.Count - 1 Then '下一张
Button2.Enabled = False
Else
FileIndex = FileIndex + 1
Button1.Enabled = True
ShowBmp()
End If
End Sub
Sub FindFiles()
Dim m As Integer
Dim t As Integer
FileListBox1.Path = BmpFilePath
ListBox1.Items.Clear()
m = 0
For t = 0 To FileListBox1.Items.Count - 1
If Microsoft.VisualBasic.Right$(FileListBox1.Items(t), 4) = ".bmp" Or Microsoft.VisualBasic.Right$(FileListBox1.Items(t), 4) = ".BMP" _
Or Microsoft.VisualBasic.Right$(FileListBox1.Items(t), 4) = ".jpg" Or Microsoft.VisualBasic.Right$(FileListBox1.Items(t), 4) = ".gif" _
Or Microsoft.VisualBasic.Right$(FileListBox1.Items(t), 4) = ".ico" Then
ListBox1.Items.Add(FileListBox1.Items(t))
If FileListBox1.Items(t) = BmpFileName Then
FileIndex = m '纪录打开的文件
End If
m = m + 1
End If
Next
End Sub
Sub ShowBmp()
PictureBox1.Image = Image.FromFile(ListBox1.Items(FileIndex)) '显示图片
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FileListBox1.Visible = False
ListBox1.Visible = False
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -