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

📄 form1.vb

📁 这是一本用Visual Studio.NET进行多媒体编程的读物
💻 VB
字号:
Option Strict Off
Option Explicit On
Friend Class Form1
	Inherits System.Windows.Forms.Form
#Region "Windows 窗体设计器生成的代码"
	Public Sub New()
		MyBase.New()
		If m_vb6FormDefInstance Is Nothing Then
			If m_InitializingDefInstance Then
				m_vb6FormDefInstance = Me
			Else
				Try 
					'对于启动窗体,所创建的第一个实例为默认实例。
					If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
						m_vb6FormDefInstance = Me
					End If
				Catch
				End Try
			End If
		End If
		'此调用是 Windows 窗体设计器所必需的。
		InitializeComponent()
	End Sub
	'窗体重写处置,以清理组件列表。
	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
	Public ToolTip1 As System.Windows.Forms.ToolTip
	Public WithEvents Picture1 As System.Windows.Forms.PictureBox
	Public WithEvents ExitButton As System.Windows.Forms.Button
	Public WithEvents JPGMake1 As AxJPGMaker.AxJPGMake
	Public WithEvents HScroll1 As System.Windows.Forms.HScrollBar
	Public WithEvents BmptoJpg As System.Windows.Forms.Button
	Public WithEvents AddPic As System.Windows.Forms.Button
	Public WithEvents cd As AxMSComDlg.AxCommonDialog
	Public WithEvents Label4 As System.Windows.Forms.Label
	Public WithEvents Label6 As System.Windows.Forms.Label
	Public WithEvents Label3 As System.Windows.Forms.Label
	Public WithEvents Label2 As System.Windows.Forms.Label
	Public WithEvents Label1 As System.Windows.Forms.Label
	'注意:以下过程是 Windows 窗体设计器所必需的
	'可以使用 Windows 窗体设计器来修改它。
	'不要使用代码编辑器来修改它。
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.Picture1 = New System.Windows.Forms.PictureBox()
        Me.ExitButton = New System.Windows.Forms.Button()
        Me.JPGMake1 = New AxJPGMaker.AxJPGMake()
        Me.HScroll1 = New System.Windows.Forms.HScrollBar()
        Me.BmptoJpg = New System.Windows.Forms.Button()
        Me.AddPic = New System.Windows.Forms.Button()
        Me.cd = New AxMSComDlg.AxCommonDialog()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        CType(Me.JPGMake1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.cd, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Picture1
        '
        Me.Picture1.BackColor = System.Drawing.SystemColors.Control
        Me.Picture1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Picture1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Picture1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Picture1.Location = New System.Drawing.Point(184, 88)
        Me.Picture1.Name = "Picture1"
        Me.Picture1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Picture1.Size = New System.Drawing.Size(113, 105)
        Me.Picture1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.Picture1.TabIndex = 8
        '
        'ExitButton
        '
        Me.ExitButton.BackColor = System.Drawing.SystemColors.Control
        Me.ExitButton.Cursor = System.Windows.Forms.Cursors.Default
        Me.ExitButton.ForeColor = System.Drawing.SystemColors.ControlText
        Me.ExitButton.Location = New System.Drawing.Point(216, 208)
        Me.ExitButton.Name = "ExitButton"
        Me.ExitButton.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.ExitButton.Size = New System.Drawing.Size(81, 25)
        Me.ExitButton.TabIndex = 6
        Me.ExitButton.Text = "退出"
        '
        'JPGMake1
        '
        Me.JPGMake1.Enabled = True
        Me.JPGMake1.Location = New System.Drawing.Point(240, 144)
        Me.JPGMake1.Name = "JPGMake1"
        Me.JPGMake1.OcxState = CType(resources.GetObject("JPGMake1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.JPGMake1.Size = New System.Drawing.Size(25, 25)
        Me.JPGMake1.TabIndex = 9
        '
        'HScroll1
        '
        Me.HScroll1.Cursor = System.Windows.Forms.Cursors.Default
        Me.HScroll1.LargeChange = 5
        Me.HScroll1.Location = New System.Drawing.Point(8, 32)
        Me.HScroll1.Maximum = 104
        Me.HScroll1.Name = "HScroll1"
        Me.HScroll1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.HScroll1.Size = New System.Drawing.Size(289, 17)
        Me.HScroll1.TabIndex = 4
        Me.HScroll1.TabStop = True
        Me.HScroll1.Value = 50
        '
        'BmptoJpg
        '
        Me.BmptoJpg.BackColor = System.Drawing.SystemColors.Control
        Me.BmptoJpg.Cursor = System.Windows.Forms.Cursors.Default
        Me.BmptoJpg.ForeColor = System.Drawing.SystemColors.ControlText
        Me.BmptoJpg.Location = New System.Drawing.Point(112, 208)
        Me.BmptoJpg.Name = "BmptoJpg"
        Me.BmptoJpg.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.BmptoJpg.Size = New System.Drawing.Size(81, 25)
        Me.BmptoJpg.TabIndex = 1
        Me.BmptoJpg.Text = "格式转化"
        '
        'AddPic
        '
        Me.AddPic.BackColor = System.Drawing.SystemColors.Control
        Me.AddPic.Cursor = System.Windows.Forms.Cursors.Default
        Me.AddPic.ForeColor = System.Drawing.SystemColors.ControlText
        Me.AddPic.Location = New System.Drawing.Point(8, 208)
        Me.AddPic.Name = "AddPic"
        Me.AddPic.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.AddPic.Size = New System.Drawing.Size(81, 25)
        Me.AddPic.TabIndex = 0
        Me.AddPic.Text = "载入BMP文件"
        '
        'cd
        '
        Me.cd.Enabled = True
        Me.cd.Location = New System.Drawing.Point(424, 0)
        Me.cd.Name = "cd"
        Me.cd.OcxState = CType(resources.GetObject("cd.OcxState"), System.Windows.Forms.AxHost.State)
        Me.cd.Size = New System.Drawing.Size(26, 26)
        Me.cd.TabIndex = 10
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.BackColor = System.Drawing.SystemColors.Control
        Me.Label4.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label4.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label4.Location = New System.Drawing.Point(184, 64)
        Me.Label4.Name = "Label4"
        Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label4.Size = New System.Drawing.Size(54, 14)
        Me.Label4.TabIndex = 9
        Me.Label4.Text = "图像预览"
        '
        'Label6
        '
        Me.Label6.BackColor = System.Drawing.SystemColors.Control
        Me.Label6.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label6.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label6.Location = New System.Drawing.Point(96, 8)
        Me.Label6.Name = "Label6"
        Me.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label6.Size = New System.Drawing.Size(49, 17)
        Me.Label6.TabIndex = 7
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.BackColor = System.Drawing.SystemColors.Control
        Me.Label3.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label3.Location = New System.Drawing.Point(8, 8)
        Me.Label3.Name = "Label3"
        Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label3.Size = New System.Drawing.Size(72, 14)
        Me.Label3.TabIndex = 5
        Me.Label3.Text = "选择压缩比:"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.BackColor = System.Drawing.SystemColors.Control
        Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label2.Location = New System.Drawing.Point(8, 64)
        Me.Label2.Name = "Label2"
        Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label2.Size = New System.Drawing.Size(134, 14)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "图像文件格式转换结果:"
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.SystemColors.Control
        Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label1.Location = New System.Drawing.Point(8, 88)
        Me.Label1.Name = "Label1"
        Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label1.Size = New System.Drawing.Size(161, 105)
        Me.Label1.TabIndex = 2
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(308, 242)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Picture1, Me.ExitButton, Me.JPGMake1, Me.HScroll1, Me.BmptoJpg, Me.AddPic, Me.cd, Me.Label4, Me.Label6, Me.Label3, Me.Label2, Me.Label1})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Location = New System.Drawing.Point(2, 21)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Form1"
        CType(Me.JPGMake1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.cd, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
#End Region 
#Region "升级支持"
	Private Shared m_vb6FormDefInstance As Form1
	Private Shared m_InitializingDefInstance As Boolean
	Public Shared Property DefInstance() As Form1
		Get
			If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
				m_InitializingDefInstance = True
				m_vb6FormDefInstance = New Form1()
				m_InitializingDefInstance = False
			End If
			DefInstance = m_vb6FormDefInstance
		End Get
		Set
			m_vb6FormDefInstance = Value
		End Set
	End Property
#End Region 
    Public Fname As String
    'Dim g As Graphics
	
	Private Sub AddPic_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles AddPic.Click
		cd.Filter = "Bitmaps (*.bmp)|*.bmp"
		cd.ShowOpen()
		Fname = cd.FileName
		JPGMake1.FileName = Fname
        Picture1.Image = Image.FromFile(Fname)
	End Sub
	
	Private Sub BmptoJpg_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles BmptoJpg.Click
		JPGMake1.Go()
        Dim bmpsize As Single
        Dim jpgsize As Single

		bmpsize = Int(FileLen(Fname) / 1024)
		jpgsize = Int(FileLen(Mid(Fname, 1, Len(Fname) - 3) & "jpg") / 1024)
        Label1.Text = "File name: " & vbCrLf & Fname & vbCrLf
        Label1.Text = Label1.Text & "BMP file size = " & CStr(bmpsize) & " KB" & vbCrLf & "JPG file size = " & CStr(jpgsize) & " KB"
	End Sub
	
	Private Sub ExitButton_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ExitButton.Click
		End
	End Sub
	
	Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		JPGMake1.Quality = 50
        Label6.Text = "50%"
        'g = Picture1.CreateGraphics
    End Sub

    Private Sub HScroll1_Change(ByVal newScrollValue As Integer)
        JPGMake1.Quality = newScrollValue
        Label6.Text = CStr(newScrollValue) & " %"
    End Sub
    Private Sub HScroll1_Scroll(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ScrollEventArgs) Handles HScroll1.Scroll
        Select Case eventArgs.Type
            Case System.Windows.Forms.ScrollEventType.EndScroll
                HScroll1_Change(eventArgs.NewValue)
        End Select
    End Sub
End Class

⌨️ 快捷键说明

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