📄 formpicviewer.vb
字号:
Public Class formPicViewer
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 MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MdiClient1 As System.Windows.Forms.MdiClient
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar
Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton
Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
Friend WithEvents mWindow As System.Windows.Forms.MenuItem
Friend WithEvents mFile As System.Windows.Forms.MenuItem
Friend WithEvents mOpen As System.Windows.Forms.MenuItem
Friend WithEvents mExit As System.Windows.Forms.MenuItem
Friend WithEvents mCascade As System.Windows.Forms.MenuItem
Friend WithEvents mVertical As System.Windows.Forms.MenuItem
Friend WithEvents mHorizontal As System.Windows.Forms.MenuItem
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents mHelp As System.Windows.Forms.MenuItem
Friend WithEvents mAbout As System.Windows.Forms.MenuItem
Friend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButton
Friend WithEvents ToolBarButton4 As System.Windows.Forms.ToolBarButton
Friend WithEvents ToolBarButton5 As System.Windows.Forms.ToolBarButton
Private components As System.ComponentModel.IContainer
'Required by the Windows Form Designer
'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.components = New System.ComponentModel.Container()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(formPicViewer))
Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton()
Me.MdiClient1 = New System.Windows.Forms.MdiClient()
Me.mWindow = New System.Windows.Forms.MenuItem()
Me.mCascade = New System.Windows.Forms.MenuItem()
Me.mHorizontal = New System.Windows.Forms.MenuItem()
Me.mVertical = New System.Windows.Forms.MenuItem()
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()
Me.ComboBox1 = New System.Windows.Forms.ComboBox()
Me.mOpen = New System.Windows.Forms.MenuItem()
Me.ToolBar1 = New System.Windows.Forms.ToolBar()
Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton()
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
Me.MainMenu1 = New System.Windows.Forms.MainMenu()
Me.mFile = New System.Windows.Forms.MenuItem()
Me.mExit = New System.Windows.Forms.MenuItem()
Me.mHelp = New System.Windows.Forms.MenuItem()
Me.mAbout = New System.Windows.Forms.MenuItem()
Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton()
Me.ToolBarButton4 = New System.Windows.Forms.ToolBarButton()
Me.ToolBarButton5 = New System.Windows.Forms.ToolBarButton()
Me.SuspendLayout()
'
'ToolBarButton2
'
Me.ToolBarButton2.ImageIndex = 1
Me.ToolBarButton2.Text = "退出"
'
'MdiClient1
'
Me.MdiClient1.Dock = System.Windows.Forms.DockStyle.Fill
Me.MdiClient1.Location = New System.Drawing.Point(0, 25)
Me.MdiClient1.Name = "MdiClient1"
Me.MdiClient1.TabIndex = 1
'
'mWindow
'
Me.mWindow.Index = 1
Me.mWindow.MdiList = True
Me.mWindow.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mCascade, Me.mHorizontal, Me.mVertical})
Me.mWindow.Text = "窗口(&W)"
'
'mCascade
'
Me.mCascade.Index = 0
Me.mCascade.Text = "层叠窗口(&C)"
'
'mHorizontal
'
Me.mHorizontal.Index = 1
Me.mHorizontal.Text = "横向平铺窗口(&H)"
'
'mVertical
'
Me.mVertical.Index = 2
Me.mVertical.Text = "纵向平铺窗口(&V)"
'
'ComboBox1
'
Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox1.DropDownWidth = 80
Me.ComboBox1.Location = New System.Drawing.Point(256, 4)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(80, 20)
Me.ComboBox1.TabIndex = 3
'
'mOpen
'
Me.mOpen.Index = 0
Me.mOpen.Text = "打开(&O)"
'
'ToolBar1
'
Me.ToolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat
Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton1, Me.ToolBarButton2, Me.ToolBarButton3, Me.ToolBarButton4, Me.ToolBarButton5})
Me.ToolBar1.ButtonSize = New System.Drawing.Size(20, 20)
Me.ToolBar1.DropDownArrows = True
Me.ToolBar1.ImageList = Me.ImageList1
Me.ToolBar1.Name = "ToolBar1"
Me.ToolBar1.ShowToolTips = True
Me.ToolBar1.Size = New System.Drawing.Size(336, 25)
Me.ToolBar1.TabIndex = 2
Me.ToolBar1.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right
'
'ToolBarButton1
'
Me.ToolBarButton1.ImageIndex = 0
Me.ToolBarButton1.Text = "打开"
'
'ImageList1
'
Me.ImageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mFile, Me.mWindow, Me.mHelp})
'
'mFile
'
Me.mFile.Index = 0
Me.mFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mOpen, Me.mExit})
Me.mFile.Text = "文件(&F)"
'
'mExit
'
Me.mExit.Index = 1
Me.mExit.Text = "退出(&X)"
'
'mHelp
'
Me.mHelp.Index = 2
Me.mHelp.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mAbout})
Me.mHelp.Text = "帮助(&H)"
'
'mAbout
'
Me.mAbout.Index = 0
Me.mAbout.Text = "关于PicViewer(&A)..."
'
'ToolBarButton3
'
Me.ToolBarButton3.ImageIndex = 2
Me.ToolBarButton3.Text = "层叠"
'
'ToolBarButton4
'
Me.ToolBarButton4.ImageIndex = 3
Me.ToolBarButton4.Text = "横向"
'
'ToolBarButton5
'
Me.ToolBarButton5.ImageIndex = 4
Me.ToolBarButton5.Text = "纵向"
'
'formPicViewer
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(336, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ComboBox1, Me.ToolBar1, Me.MdiClient1})
Me.IsMdiContainer = True
Me.Menu = Me.MainMenu1
Me.Name = "formPicViewer"
Me.Text = "PicViewer"
Me.ResumeLayout(False)
End Sub
#End Region
Dim filterIndex As Int32
'用于记录过滤器索引值
Dim FormCount As Integer
'用于记录打开的窗体的数目
Private Sub formPicViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
filterIndex = -1
FormCount = 0
ComboBox1.Items.Add("层叠窗口")
ComboBox1.Items.Add("横向平铺窗口")
ComboBox1.Items.Add("纵向平铺窗口")
End Sub
Private Sub subFileOpen()
OpenFileDialog1.Filter = "Image files (JPeg, Gif, Bmp, etc.)|*.jpg;*.jpeg;*.gif;*.bmp;*.tif;*.tiff;*.png" & "|JPeg files (*.jpg;*.jpeg)|*.jpg;*.jpeg" & "|GIF files (*.gif)|*.gif" & "|BMP files (*.bmp)|*.bmp" & "|Tiff files (*.tif;*.tiff)|*.tif;*.tiff" & "|Png files (*.png)|*.png" & "|All files (*.*)|*.*"
'文件类型过滤器
If filterIndex <> -1 Then
OpenFileDialog1.FilterIndex = filterIndex
End If
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim strFileName As String
strFileName = OpenFileDialog1.FileName
'获得文件名
If strFileName.Length <> 0 Then
filterIndex = OpenFileDialog1.FilterIndex
Try
Dim img As New Bitmap(strFileName)
Dim frmTemp As New formChild()
frmTemp.MdiParent = Me
'定义此窗体的父窗体,从而此窗体成为一个MDI窗体
frmTemp.WindowState = FormWindowState.Maximized
'使窗体一开始就最大
frmTemp.PictureBox1.Image = img
'设置图片()
frmTemp.AutoScroll = True
frmTemp.Text = strFileName
'设定MDI窗体的标题
FormCount = FormCount + 1
'窗体数目增加一
frmTemp.Show()
'把此MDI窗体显示出来
Catch
MessageBox.Show(String.Format("{0} is not a valid image file", strFileName), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End If
End If
End Sub
Private Sub mOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mOpen.Click
subFileOpen()
'打开图像文件
End Sub
Private Sub mExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mExit.Click
Close()
'退出
End Sub
Private Sub mCascade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mCascade.Click
Me.LayoutMdi(MdiLayout.Cascade)
ComboBox1.Text = "层叠窗口"
'层叠窗口
End Sub
Private Sub mHorizontal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mHorizontal.Click
Me.LayoutMdi(MdiLayout.TileHorizontal)
ComboBox1.Text = "横向平铺窗口"
'横向平铺窗口
End Sub
Private Sub mVertical_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mVertical.Click
Me.LayoutMdi(MdiLayout.TileVertical)
ComboBox1.Text = "纵向平铺窗口"
'纵向平铺窗口
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Select Case ComboBox1.Text
Case "层叠窗口"
Me.LayoutMdi(MdiLayout.Cascade)
Case "横向平铺窗口"
Me.LayoutMdi(MdiLayout.TileHorizontal)
Case "纵向平铺窗口"
Me.LayoutMdi(MdiLayout.TileVertical)
End Select
End Sub
Private Sub ToolBar1_ButtonClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
Select Case ToolBar1.Buttons.IndexOf(e.Button)
Case 0
subFileOpen()
'打开图像文件
Case 1
Close()
'退出
Case 2
Me.LayoutMdi(MdiLayout.Cascade)
ComboBox1.Text = "层叠窗口"
'层叠窗口
Case 3
Me.LayoutMdi(MdiLayout.TileHorizontal)
ComboBox1.Text = "横向平铺窗口"
'横向平铺窗口
Case 4
Me.LayoutMdi(MdiLayout.TileVertical)
ComboBox1.Text = "纵向平铺窗口"
'纵向平铺窗口
End Select
'根据点击的ToolBar中的Button的索引值来判断用户点击的按钮
End Sub
Private Sub mAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mAbout.Click
Dim fAbout As New FormAbout()
fAbout.Show()
'显示“关于”窗口
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -