EDN Admin
Well-known member
I am having difficulties with getting a PictureBox to resize its contents properly. I have read through my code, and cannot find any issues. I was wondering if there might be something Im overlooking? I am using Microsoft Visual Basic 2010 Express version
10.0.30319.1. I am using an HP-Pavilion PC with a Pentium(R) Dual-Core CPU E5300 Processor. Here is the code, which I copy-pasted from my project. Underneath it is the designer code.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Public <span style="color:Blue; Class Form1
<span style="color:Blue; Private <span style="color:Blue; Sub Form1_Load(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles <span style="color:Blue; MyBase.Load
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub closeButton_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles closeButton.Click
<span style="color:Green; Close the form.
Close()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub backgroundButton_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles backgroundButton.Click
<span style="color:Green; Show the color dialog box. If the user clicks OK, change the PictureBox controls background to the color the user chose.
<span style="color:Blue; If ColorDialog1.ShowDialog() = DialogResult.OK <span style="color:Blue; Then
PictureBox1.BackColor = ColorDialog1.Color
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub clearButton_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles clearButton.Click
<span style="color:Green; Clear the picture.
PictureBox1.Image = <span style="color:Blue; Nothing
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub showButton_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles showButton.Click
<span style="color:Green; Show the Open File dialog. If the user clicks OK, load the picture that the user chose.
<span style="color:Blue; If OpenFileDialog1.ShowDialog() = DialogResult.OK <span style="color:Blue; Then
PictureBox1.Load(OpenFileDialog1.FileName)
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub stretchButton_CheckedChanged(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs)
<span style="color:Green; If the user selects the Stretch radio button, change the PictureBoxs SizeMode property to "Stretch".
<span style="color:Blue; If stretchButton.Checked <span style="color:Blue; Then
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub autozoomButton_CheckedChanged(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs)
<span style="color:Green; If the user selects the AutoZoom radio button, change the PictureBoxs SizeMode property to "Zoom"
<span style="color:Blue; If autozoomButton.Checked <span style="color:Blue; Then
PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub normalButton_CheckedChanged(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles normalButton.CheckedChanged
<span style="color:Green; If the user selects the Original Size radio button, change the PictureBoxs SizeMode property to "Normal".
<span style="color:Blue; If normalButton.Checked <span style="color:Blue; Then
PictureBox1.SizeMode = PictureBoxSizeMode.Normal
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Class
<pre><Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<span style="color:Blue; Partial <span style="color:Blue; Class Form1
<span style="color:Blue; Inherits System.Windows.Forms.Form
<span style="color:Green; Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
<span style="color:Blue; Protected <span style="color:Blue; Overrides <span style="color:Blue; Sub Dispose(<span style="color:Blue; ByVal disposing <span style="color:Blue; As <span style="color:Blue; Boolean)
<span style="color:Blue; Try
<span style="color:Blue; If disposing <span style="color:Blue; AndAlso components <span style="color:Blue; IsNot <span style="color:Blue; Nothing <span style="color:Blue; Then
components.Dispose()
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Finally
<span style="color:Blue; MyBase.Dispose(disposing)
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Green; Required by the Windows Form Designer
<span style="color:Blue; Private components <span style="color:Blue; As System.ComponentModel.IContainer
<span style="color:Green; NOTE: The following procedure is required by the Windows Form Designer
<span style="color:Green; It can be modified using the Windows Form Designer.
<span style="color:Green; Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
<span style="color:Blue; Private <span style="color:Blue; Sub InitializeComponent()
<span style="color:Blue; Me.OpenFileDialog1 = <span style="color:Blue; New System.Windows.Forms.OpenFileDialog()
<span style="color:Blue; Me.ColorDialog1 = <span style="color:Blue; New System.Windows.Forms.ColorDialog()
<span style="color:Blue; Me.PictureBox1 = <span style="color:Blue; New System.Windows.Forms.PictureBox()
<span style="color:Blue; Me.FlowLayoutPanel1 = <span style="color:Blue; New System.Windows.Forms.FlowLayoutPanel()
<span style="color:Blue; Me.closeButton = <span style="color:Blue; New System.Windows.Forms.Button()
<span style="color:Blue; Me.backgroundButton = <span style="color:Blue; New System.Windows.Forms.Button()
<span style="color:Blue; Me.clearButton = <span style="color:Blue; New System.Windows.Forms.Button()
<span style="color:Blue; Me.showButton = <span style="color:Blue; New System.Windows.Forms.Button()
<span style="color:Blue; Me.FlowLayoutPanel2 = <span style="color:Blue; New System.Windows.Forms.FlowLayoutPanel()
<span style="color:Blue; Me.stretchButton = <span style="color:Blue; New System.Windows.Forms.RadioButton()
<span style="color:Blue; Me.normalButton = <span style="color:Blue; New System.Windows.Forms.RadioButton()
<span style="color:Blue; Me.autozoomButton = <span style="color:Blue; New System.Windows.Forms.RadioButton()
<span style="color:Blue; Me.TableLayoutPanel1 = <span style="color:Blue; New System.Windows.Forms.TableLayoutPanel()
<span style="color:Blue; CType(<span style="color:Blue; Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
<span style="color:Blue; Me.FlowLayoutPanel1.SuspendLayout()
<span style="color:Blue; Me.FlowLayoutPanel2.SuspendLayout()
<span style="color:Blue; Me.TableLayoutPanel1.SuspendLayout()
<span style="color:Blue; Me.SuspendLayout()
<span style="color:Green;
<span style="color:Green; OpenFileDialog1
<span style="color:Green;
<span style="color:Blue; Me.OpenFileDialog1.FileName = <span style="color:#A31515; "OpenFileDialog1"
<span style="color:Blue; Me.OpenFileDialog1.Filter = <span style="color:#A31515; "JPEG Files (*.jpg)|*.jpg|PNG Files (*.png)|*.png|BMP Files (*.bmp)|*.bmp|All file" & _
<span style="color:#A31515; "s (*.*)|*.*"
<span style="color:Blue; Me.OpenFileDialog1.Title = <span style="color:#A31515; "Select a picture file"
<span style="color:Green;
<span style="color:Green; PictureBox1
<span style="color:Green;
<span style="color:Blue; Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
<span style="color:Blue; Me.TableLayoutPanel1.SetColumnSpan(<span style="color:Blue; Me.PictureBox1, 2)
<span style="color:Blue; Me.PictureBox1.Dock = System.Windows.Forms.DockStyle.Fill
<span style="color:Blue; Me.PictureBox1.Location = <span style="color:Blue; New System.Drawing.Point(3, 3)
<span style="color:Blue; Me.PictureBox1.Name = <span style="color:#A31515; "PictureBox1"
<span style="color:Blue; Me.PictureBox1.Size = <span style="color:Blue; New System.Drawing.Size(659, 270)
<span style="color:Blue; Me.PictureBox1.TabIndex = 0
<span style="color:Blue; Me.PictureBox1.TabStop = <span style="color:Blue; False
<span style="color:Green;
<span style="color:Green; FlowLayoutPanel1
<span style="color:Green;
<span style="color:Blue; Me.FlowLayoutPanel1.Controls.Add(<span style="color:Blue; Me.showButton)
<span style="color:Blue; Me.FlowLayoutPanel1.Controls.Add(<span style="color:Blue; Me.clearButton)
<span style="color:Blue; Me.FlowLayoutPanel1.Controls.Add(<span style="color:Blue; Me.backgroundButton)
<span style="color:Blue; Me.FlowLayoutPanel1.Controls.Add(<span style="color:Blue; Me.closeButton)
<span style="color:Blue; Me.FlowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Right
<span style="color:Blue; Me.FlowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft
<span style="color:Blue; Me.FlowLayoutPanel1.Location = <span style="color:Blue; New System.Drawing.Point(244, 279)
<span style="color:Blue; Me.FlowLayoutPanel1.Name = <span style="color:#A31515; "FlowLayoutPanel1"
<span style="color:Blue; Me.FlowLayoutPanel1.Size = <span style="color:Blue; New System.Drawing.Size(418, 29)
<span style="color:Blue; Me.FlowLayoutPanel1.TabIndex = 2
<span style="color:Green;
<span style="color:Green; closeButton
<span style="color:Green;
<span style="color:Blue; Me.closeButton.AutoSize = <span style="color:Blue; True
<span style="color:Blue; Me.closeButton.DialogResult = System.Windows.Forms.DialogResult.Cancel
<span style="color:Blue; Me.closeButton.Location = <span style="color:Blue; New System.Drawing.Point(3, 3)
<span style="color:Blue; Me.closeButton.Name = <span style="color:#A31515; "closeButton"
<span style="color:Blue; Me.closeButton.Size = <span style="color:Blue; New System.Drawing.Size(75, 23)
<span style="color:Blue; Me.closeButton.TabIndex = 3
<span style="color:Blue; Me.closeButton.Text = <span style="color:#A31515; "Close"
<span style="color:Blue; Me.closeButton.UseVisualStyleBackColor = <span style="color:Blue; True
<span style="color:Green;
<span style="color:Green; backgroundButton
<span style="color:Green;
<span style="color:Blue; Me.backgroundButton.AutoSize = <span style="color:Blue; True
<span style="color:Blue; Me.backgroundButton.Location = <span style="color:Blue; New System.Drawing.Point(84, 3)
<span style="color:Blue; Me.backgroundButton.Name = <span style="color:#A31515; "backgroundButton"
<span style="color:Blue; Me.backgroundButton.Size = <span style="color:Blue; New System.Drawing.Size(137, 23)
<span style="color:Blue; Me.backgroundButton.TabIndex = 2
<span style="color:Blue; Me.backgroundButton.Text = <span style="color:#A31515; "Set the background color"
<span style="color:Blue; Me.backgroundButton.UseVisualStyleBackColor = <span style="color:Blue; True
<span style="color:Green;
<span style="color:Green; clearButton
<span style="color:Green;
<span style="color:Blue; Me.clearButton.AutoSize = <span style="color:Blue; True
<span style="color:Blue; Me.clearButton.Location = <span style="color:Blue; New System.Drawing.Point(227, 3)
<span style="color:Blue; Me.clearButton.Name = <span style="color:#A31515; "clearButton"
<span style="color:Blue; Me.clearButton.Size = <span style="color:Blue; New System.Drawing.Size(94, 23)
<span style="color:Blue; Me.clearButton.TabIndex = 1
<span style="color:Blue; Me.clearButton.Text = <span style="color:#A31515; "Clear the picture"
<span style="color:Blue; Me.clearButton.UseVisualStyleBackColor = <span style="color:Blue; True
<span style="color:Green;
<span style="color:Green; showButton
<span style="color:Green;
<span style="color:Blue; Me.showButton.AutoSize = <span style="color:Blue; True
<span style="color:Blue; Me.showButton.Location = <span style="color:Blue; New System.Drawing.Point(327, 3)
<span style="color:Blue; Me.showButton.Name = <span style="color:#A31515; "showButton"
<span style="color:Blue; Me.showButton.Size = <span style="color:Blue; New System.Drawing.Size(88, 23)
<span style="color:Blue; Me.showButton.TabIndex = 0
<span style="color:Blue; Me.showButton.Text = <span style="color:#A31515; "Show a picture"
<span style="color:Blue; Me.showButton.UseVisualStyleBackColor = <span style="color:Blue; True
<span style="color:Green;
<span style="color:Green; FlowLayoutPanel2
<span style="color:Green;
<span style="color:Blue; Me.FlowLayoutPanel2.Controls.Add(<span style="color:Blue; Me.autozoomButton)
<span style="color:Blue; Me.FlowLayoutPanel2.Controls.Add(<span style="color:Blue; Me.normalButton)
<span style="color:Blue; Me.FlowLayoutPanel2.Controls.Add(<span style="color:Blue; Me.stretchButton)
<span style="color:Blue; Me.FlowLayoutPanel2.Location = <span style="color:Blue; New System.Drawing.Point(3, 279)
<span style="color:Blue; Me.FlowLayoutPanel2.Name = <span style="color:#A31515; "FlowLayoutPanel2"
<span style="color:Blue; Me.FlowLayoutPanel2.Size = <span style="color:Blue; New System.Drawing.Size(234, 23)
<span style="color:Blue; Me.FlowLayoutPanel2.TabIndex = 3
<span style="color:Green;
<span style="color:Green; stretchButton
<span style="color:Green;
<span style="color:Blue; Me.stretchButton.AutoSize = <span style="color:Blue; True
<span style="color:Blue; Me.stretchButton.Location = <span style="color:Blue; New System.Drawing.Point(172, 3)
<span style="color:Blue; Me.stretchButton.Name = <span style="color:#A31515; "stretchButton"
<span style="color:Blue; Me.stretchButton.Size = <span style="color:Blue; New System.Drawing.Size(59, 17)
<span style="color:Blue; Me.stretchButton.TabIndex = 3
<span style="color:Blue; Me.stretchButton.Text = <span style="color:#A31515; "Stretch"
<span style="color:Blue; Me.stretchButton.UseVisualStyleBackColor = <span style="color:Blue; True
<span style="color:Green;
<span style="color:Green; normalButton
<span style="color:Green;
<span style="color:Blue; Me.normalButton.AutoSize = <span style="color:Blue; True
<span style="color:Blue; Me.normalButton.Location = <span style="color:Blue; New System.Drawing.Point(83, 3)
<span style="color:Blue; Me.normalButton.Name = <span style="color:#A31515; "normalButton"
<span style="color:Blue; Me.normalButton.Size = <span style="color:Blue; New System.Drawing.Size(83, 17)
<span style="color:Blue; Me.normalButton.TabIndex = 5
<span style="color:Blue; Me.normalButton.Text = <span style="color:#A31515; "Original Size"
<span style="color:Blue; Me.normalButton.UseVisualStyleBackColor = <span style="color:Blue; True
<span style="color:Green;
<span style="color:Green; autozoomButton
<span style="color:Green;
<span style="color:Blue; Me.autozoomButton.AutoSize = <span style="color:Blue; True
<span style="color:Blue; Me.autozoomButton.Checked = <span style="color:Blue; True
<span style="color:Blue; Me.autozoomButton.Location = <span style="color:Blue; New System.Drawing.Point(3, 3)
<span style="color:Blue; Me.autozoomButton.Name = <span style="color:#A31515; "autozoomButton"
<span style="color:Blue; Me.autozoomButton.Size = <span style="color:Blue; New System.Drawing.Size(74, 17)
<span style="color:Blue; Me.autozoomButton.TabIndex = 4
<span style="color:Blue; Me.autozoomButton.TabStop = <span style="color:Blue; True
<span style="color:Blue; Me.autozoomButton.Text = <span style="color:#A31515; "AutoZoom"
<span style="color:Blue; Me.autozoomButton.UseVisualStyleBackColor = <span style="color:Blue; True
<span style="color:Green;
<span style="color:Green; TableLayoutPanel1
<span style="color:Green;
<span style="color:Blue; Me.TableLayoutPanel1.ColumnCount = 2
<span style="color:Blue; Me.TableLayoutPanel1.ColumnStyles.Add(<span style="color:Blue; New System.Windows.Forms.ColumnStyle())
<span style="color:Blue; Me.TableLayoutPanel1.ColumnStyles.Add(<span style="color:Blue; New System.Windows.Forms.ColumnStyle())
<span style="color:Blue; Me.TableLayoutPanel1.Controls.Add(<span style="color:Blue; Me.FlowLayoutPanel2, 0, 1)
<span style="color:Blue; Me.TableLayoutPanel1.Controls.Add(<span style="color:Blue; Me.PictureBox1, 0, 0)
<span style="color:Blue; Me.TableLayoutPanel1.Controls.Add(<span style="color:Blue; Me.FlowLayoutPanel1, 1, 1)
<span style="color:Blue; Me.TableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill
<span style="color:Blue; Me.TableLayoutPanel1.Location = <span style="color:Blue; New System.Drawing.Point(0, 0)
<span style="color:Blue; Me.TableLayoutPanel1.Name = <span style="color:#A31515; "TableLayoutPanel1"
<span style="color:Blue; Me.TableLayoutPanel1.RowCount = 2
<span style="color:Blue; Me.TableLayoutPanel1.RowStyles.Add(<span style="color:Blue; New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100.0!))
<span style="color:Blue; Me.TableLayoutPanel1.RowStyles.Add(<span style="color:Blue; New System.Windows.Forms.RowStyle())
<span style="color:Blue; Me.TableLayoutPanel1.Size = <span style="color:Blue; New System.Drawing.Size(665, 311)
<span style="color:Blue; Me.TableLayoutPanel1.TabIndex = 4
<span style="color:Green;
<span style="color:Green; Form1
<span style="color:Green;
<span style="color:Blue; Me.AcceptButton = <span style="color:Blue; Me.showButton
<span style="color:Blue; Me.AutoScaleDimensions = <span style="color:Blue; New System.Drawing.SizeF(6.0!, 13.0!)
<span style="color:Blue; Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
<span style="color:Blue; Me.CancelButton = <span style="color:Blue; Me.closeButton
<span style="color:Blue; Me.ClientSize = <span style="color:Blue; New System.Drawing.Size(665, 311)
<span style="color:Blue; Me.Controls.Add(<span style="color:Blue; Me.TableLayoutPanel1)
<span style="color:Blue; Me.MinimumSize = <span style="color:Blue; New System.Drawing.Size(681, 100)
<span style="color:Blue; Me.Name = <span style="color:#A31515; "Form1"
<span style="color:Blue; Me.Text = <span style="color:#A31515; "Picture Viewer"
<span style="color:Blue; CType(<span style="color:Blue; Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
<span style="color:Blue; Me.FlowLayoutPanel1.ResumeLayout(<span style="color:Blue; False)
<span style="color:Blue; Me.FlowLayoutPanel1.PerformLayout()
<span style="color:Blue; Me.FlowLayoutPanel2.ResumeLayout(<span style="color:Blue; False)
<span style="color:Blue; Me.FlowLayoutPanel2.PerformLayout()
<span style="color:Blue; Me.TableLayoutPanel1.ResumeLayout(<span style="color:Blue; False)
<span style="color:Blue; Me.ResumeLayout(<span style="color:Blue; False)
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Friend <span style="color:Blue; WithEvents OpenFileDialog1 <span style="color:Blue; As System.Windows.Forms.OpenFileDialog
<span style="color:Blue; Friend <span style="color:Blue; WithEvents ColorDialog1 <span style="color:Blue; As System.Windows.Forms.ColorDialog
<span style="color:Blue; Friend <span style="color:Blue; WithEvents PictureBox1 <span style="color:Blue; As System.Windows.Forms.PictureBox
<span style="color:Blue; Friend <span style="color:Blue; WithEvents TableLayoutPanel1 <span style="color:Blue; As System.Windows.Forms.TableLayoutPanel
<span style="color:Blue; Friend <span style="color:Blue; WithEvents FlowLayoutPanel2 <span style="color:Blue; As System.Windows.Forms.FlowLayoutPanel
<span style="color:Blue; Friend <span style="color:Blue; WithEvents autozoomButton <span style="color:Blue; As System.Windows.Forms.RadioButton
<span style="color:Blue; Friend <span style="color:Blue; WithEvents normalButton <span style="color:Blue; As System.Windows.Forms.RadioButton
<span style="color:Blue; Friend <span style="color:Blue; WithEvents stretchButton <span style="color:Blue; As System.Windows.Forms.RadioButton
<span style="color:Blue; Friend <span style="color:Blue; WithEvents FlowLayoutPanel1 <span style="color:Blue; As System.Windows.Forms.FlowLayoutPanel
<span style="color:Blue; Friend <span style="color:Blue; WithEvents showButton <span style="color:Blue; As System.Windows.Forms.Button
<span style="color:Blue; Friend <span style="color:Blue; WithEvents clearButton <span style="color:Blue; As System.Windows.Forms.Button
<span style="color:Blue; Friend <span style="color:Blue; WithEvents backgroundButton <span style="color:Blue; As System.Windows.Forms.Button
<span style="color:Blue; Friend <span style="color:Blue; WithEvents closeButton <span style="color:Blue; As System.Windows.Forms.Button
<span style="color:Blue; End <span style="color:Blue; Class
[/code]
[/code]
View the full article
10.0.30319.1. I am using an HP-Pavilion PC with a Pentium(R) Dual-Core CPU E5300 Processor. Here is the code, which I copy-pasted from my project. Underneath it is the designer code.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Public <span style="color:Blue; Class Form1
<span style="color:Blue; Private <span style="color:Blue; Sub Form1_Load(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles <span style="color:Blue; MyBase.Load
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub closeButton_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles closeButton.Click
<span style="color:Green; Close the form.
Close()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub backgroundButton_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles backgroundButton.Click
<span style="color:Green; Show the color dialog box. If the user clicks OK, change the PictureBox controls background to the color the user chose.
<span style="color:Blue; If ColorDialog1.ShowDialog() = DialogResult.OK <span style="color:Blue; Then
PictureBox1.BackColor = ColorDialog1.Color
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub clearButton_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles clearButton.Click
<span style="color:Green; Clear the picture.
PictureBox1.Image = <span style="color:Blue; Nothing
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub showButton_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles showButton.Click
<span style="color:Green; Show the Open File dialog. If the user clicks OK, load the picture that the user chose.
<span style="color:Blue; If OpenFileDialog1.ShowDialog() = DialogResult.OK <span style="color:Blue; Then
PictureBox1.Load(OpenFileDialog1.FileName)
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub stretchButton_CheckedChanged(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs)
<span style="color:Green; If the user selects the Stretch radio button, change the PictureBoxs SizeMode property to "Stretch".
<span style="color:Blue; If stretchButton.Checked <span style="color:Blue; Then
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub autozoomButton_CheckedChanged(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs)
<span style="color:Green; If the user selects the AutoZoom radio button, change the PictureBoxs SizeMode property to "Zoom"
<span style="color:Blue; If autozoomButton.Checked <span style="color:Blue; Then
PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub normalButton_CheckedChanged(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles normalButton.CheckedChanged
<span style="color:Green; If the user selects the Original Size radio button, change the PictureBoxs SizeMode property to "Normal".
<span style="color:Blue; If normalButton.Checked <span style="color:Blue; Then
PictureBox1.SizeMode = PictureBoxSizeMode.Normal
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Class
<pre><Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<span style="color:Blue; Partial <span style="color:Blue; Class Form1
<span style="color:Blue; Inherits System.Windows.Forms.Form
<span style="color:Green; Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
<span style="color:Blue; Protected <span style="color:Blue; Overrides <span style="color:Blue; Sub Dispose(<span style="color:Blue; ByVal disposing <span style="color:Blue; As <span style="color:Blue; Boolean)
<span style="color:Blue; Try
<span style="color:Blue; If disposing <span style="color:Blue; AndAlso components <span style="color:Blue; IsNot <span style="color:Blue; Nothing <span style="color:Blue; Then
components.Dispose()
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Finally
<span style="color:Blue; MyBase.Dispose(disposing)
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Green; Required by the Windows Form Designer
<span style="color:Blue; Private components <span style="color:Blue; As System.ComponentModel.IContainer
<span style="color:Green; NOTE: The following procedure is required by the Windows Form Designer
<span style="color:Green; It can be modified using the Windows Form Designer.
<span style="color:Green; Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
<span style="color:Blue; Private <span style="color:Blue; Sub InitializeComponent()
<span style="color:Blue; Me.OpenFileDialog1 = <span style="color:Blue; New System.Windows.Forms.OpenFileDialog()
<span style="color:Blue; Me.ColorDialog1 = <span style="color:Blue; New System.Windows.Forms.ColorDialog()
<span style="color:Blue; Me.PictureBox1 = <span style="color:Blue; New System.Windows.Forms.PictureBox()
<span style="color:Blue; Me.FlowLayoutPanel1 = <span style="color:Blue; New System.Windows.Forms.FlowLayoutPanel()
<span style="color:Blue; Me.closeButton = <span style="color:Blue; New System.Windows.Forms.Button()
<span style="color:Blue; Me.backgroundButton = <span style="color:Blue; New System.Windows.Forms.Button()
<span style="color:Blue; Me.clearButton = <span style="color:Blue; New System.Windows.Forms.Button()
<span style="color:Blue; Me.showButton = <span style="color:Blue; New System.Windows.Forms.Button()
<span style="color:Blue; Me.FlowLayoutPanel2 = <span style="color:Blue; New System.Windows.Forms.FlowLayoutPanel()
<span style="color:Blue; Me.stretchButton = <span style="color:Blue; New System.Windows.Forms.RadioButton()
<span style="color:Blue; Me.normalButton = <span style="color:Blue; New System.Windows.Forms.RadioButton()
<span style="color:Blue; Me.autozoomButton = <span style="color:Blue; New System.Windows.Forms.RadioButton()
<span style="color:Blue; Me.TableLayoutPanel1 = <span style="color:Blue; New System.Windows.Forms.TableLayoutPanel()
<span style="color:Blue; CType(<span style="color:Blue; Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
<span style="color:Blue; Me.FlowLayoutPanel1.SuspendLayout()
<span style="color:Blue; Me.FlowLayoutPanel2.SuspendLayout()
<span style="color:Blue; Me.TableLayoutPanel1.SuspendLayout()
<span style="color:Blue; Me.SuspendLayout()
<span style="color:Green;
<span style="color:Green; OpenFileDialog1
<span style="color:Green;
<span style="color:Blue; Me.OpenFileDialog1.FileName = <span style="color:#A31515; "OpenFileDialog1"
<span style="color:Blue; Me.OpenFileDialog1.Filter = <span style="color:#A31515; "JPEG Files (*.jpg)|*.jpg|PNG Files (*.png)|*.png|BMP Files (*.bmp)|*.bmp|All file" & _
<span style="color:#A31515; "s (*.*)|*.*"
<span style="color:Blue; Me.OpenFileDialog1.Title = <span style="color:#A31515; "Select a picture file"
<span style="color:Green;
<span style="color:Green; PictureBox1
<span style="color:Green;
<span style="color:Blue; Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
<span style="color:Blue; Me.TableLayoutPanel1.SetColumnSpan(<span style="color:Blue; Me.PictureBox1, 2)
<span style="color:Blue; Me.PictureBox1.Dock = System.Windows.Forms.DockStyle.Fill
<span style="color:Blue; Me.PictureBox1.Location = <span style="color:Blue; New System.Drawing.Point(3, 3)
<span style="color:Blue; Me.PictureBox1.Name = <span style="color:#A31515; "PictureBox1"
<span style="color:Blue; Me.PictureBox1.Size = <span style="color:Blue; New System.Drawing.Size(659, 270)
<span style="color:Blue; Me.PictureBox1.TabIndex = 0
<span style="color:Blue; Me.PictureBox1.TabStop = <span style="color:Blue; False
<span style="color:Green;
<span style="color:Green; FlowLayoutPanel1
<span style="color:Green;
<span style="color:Blue; Me.FlowLayoutPanel1.Controls.Add(<span style="color:Blue; Me.showButton)
<span style="color:Blue; Me.FlowLayoutPanel1.Controls.Add(<span style="color:Blue; Me.clearButton)
<span style="color:Blue; Me.FlowLayoutPanel1.Controls.Add(<span style="color:Blue; Me.backgroundButton)
<span style="color:Blue; Me.FlowLayoutPanel1.Controls.Add(<span style="color:Blue; Me.closeButton)
<span style="color:Blue; Me.FlowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Right
<span style="color:Blue; Me.FlowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft
<span style="color:Blue; Me.FlowLayoutPanel1.Location = <span style="color:Blue; New System.Drawing.Point(244, 279)
<span style="color:Blue; Me.FlowLayoutPanel1.Name = <span style="color:#A31515; "FlowLayoutPanel1"
<span style="color:Blue; Me.FlowLayoutPanel1.Size = <span style="color:Blue; New System.Drawing.Size(418, 29)
<span style="color:Blue; Me.FlowLayoutPanel1.TabIndex = 2
<span style="color:Green;
<span style="color:Green; closeButton
<span style="color:Green;
<span style="color:Blue; Me.closeButton.AutoSize = <span style="color:Blue; True
<span style="color:Blue; Me.closeButton.DialogResult = System.Windows.Forms.DialogResult.Cancel
<span style="color:Blue; Me.closeButton.Location = <span style="color:Blue; New System.Drawing.Point(3, 3)
<span style="color:Blue; Me.closeButton.Name = <span style="color:#A31515; "closeButton"
<span style="color:Blue; Me.closeButton.Size = <span style="color:Blue; New System.Drawing.Size(75, 23)
<span style="color:Blue; Me.closeButton.TabIndex = 3
<span style="color:Blue; Me.closeButton.Text = <span style="color:#A31515; "Close"
<span style="color:Blue; Me.closeButton.UseVisualStyleBackColor = <span style="color:Blue; True
<span style="color:Green;
<span style="color:Green; backgroundButton
<span style="color:Green;
<span style="color:Blue; Me.backgroundButton.AutoSize = <span style="color:Blue; True
<span style="color:Blue; Me.backgroundButton.Location = <span style="color:Blue; New System.Drawing.Point(84, 3)
<span style="color:Blue; Me.backgroundButton.Name = <span style="color:#A31515; "backgroundButton"
<span style="color:Blue; Me.backgroundButton.Size = <span style="color:Blue; New System.Drawing.Size(137, 23)
<span style="color:Blue; Me.backgroundButton.TabIndex = 2
<span style="color:Blue; Me.backgroundButton.Text = <span style="color:#A31515; "Set the background color"
<span style="color:Blue; Me.backgroundButton.UseVisualStyleBackColor = <span style="color:Blue; True
<span style="color:Green;
<span style="color:Green; clearButton
<span style="color:Green;
<span style="color:Blue; Me.clearButton.AutoSize = <span style="color:Blue; True
<span style="color:Blue; Me.clearButton.Location = <span style="color:Blue; New System.Drawing.Point(227, 3)
<span style="color:Blue; Me.clearButton.Name = <span style="color:#A31515; "clearButton"
<span style="color:Blue; Me.clearButton.Size = <span style="color:Blue; New System.Drawing.Size(94, 23)
<span style="color:Blue; Me.clearButton.TabIndex = 1
<span style="color:Blue; Me.clearButton.Text = <span style="color:#A31515; "Clear the picture"
<span style="color:Blue; Me.clearButton.UseVisualStyleBackColor = <span style="color:Blue; True
<span style="color:Green;
<span style="color:Green; showButton
<span style="color:Green;
<span style="color:Blue; Me.showButton.AutoSize = <span style="color:Blue; True
<span style="color:Blue; Me.showButton.Location = <span style="color:Blue; New System.Drawing.Point(327, 3)
<span style="color:Blue; Me.showButton.Name = <span style="color:#A31515; "showButton"
<span style="color:Blue; Me.showButton.Size = <span style="color:Blue; New System.Drawing.Size(88, 23)
<span style="color:Blue; Me.showButton.TabIndex = 0
<span style="color:Blue; Me.showButton.Text = <span style="color:#A31515; "Show a picture"
<span style="color:Blue; Me.showButton.UseVisualStyleBackColor = <span style="color:Blue; True
<span style="color:Green;
<span style="color:Green; FlowLayoutPanel2
<span style="color:Green;
<span style="color:Blue; Me.FlowLayoutPanel2.Controls.Add(<span style="color:Blue; Me.autozoomButton)
<span style="color:Blue; Me.FlowLayoutPanel2.Controls.Add(<span style="color:Blue; Me.normalButton)
<span style="color:Blue; Me.FlowLayoutPanel2.Controls.Add(<span style="color:Blue; Me.stretchButton)
<span style="color:Blue; Me.FlowLayoutPanel2.Location = <span style="color:Blue; New System.Drawing.Point(3, 279)
<span style="color:Blue; Me.FlowLayoutPanel2.Name = <span style="color:#A31515; "FlowLayoutPanel2"
<span style="color:Blue; Me.FlowLayoutPanel2.Size = <span style="color:Blue; New System.Drawing.Size(234, 23)
<span style="color:Blue; Me.FlowLayoutPanel2.TabIndex = 3
<span style="color:Green;
<span style="color:Green; stretchButton
<span style="color:Green;
<span style="color:Blue; Me.stretchButton.AutoSize = <span style="color:Blue; True
<span style="color:Blue; Me.stretchButton.Location = <span style="color:Blue; New System.Drawing.Point(172, 3)
<span style="color:Blue; Me.stretchButton.Name = <span style="color:#A31515; "stretchButton"
<span style="color:Blue; Me.stretchButton.Size = <span style="color:Blue; New System.Drawing.Size(59, 17)
<span style="color:Blue; Me.stretchButton.TabIndex = 3
<span style="color:Blue; Me.stretchButton.Text = <span style="color:#A31515; "Stretch"
<span style="color:Blue; Me.stretchButton.UseVisualStyleBackColor = <span style="color:Blue; True
<span style="color:Green;
<span style="color:Green; normalButton
<span style="color:Green;
<span style="color:Blue; Me.normalButton.AutoSize = <span style="color:Blue; True
<span style="color:Blue; Me.normalButton.Location = <span style="color:Blue; New System.Drawing.Point(83, 3)
<span style="color:Blue; Me.normalButton.Name = <span style="color:#A31515; "normalButton"
<span style="color:Blue; Me.normalButton.Size = <span style="color:Blue; New System.Drawing.Size(83, 17)
<span style="color:Blue; Me.normalButton.TabIndex = 5
<span style="color:Blue; Me.normalButton.Text = <span style="color:#A31515; "Original Size"
<span style="color:Blue; Me.normalButton.UseVisualStyleBackColor = <span style="color:Blue; True
<span style="color:Green;
<span style="color:Green; autozoomButton
<span style="color:Green;
<span style="color:Blue; Me.autozoomButton.AutoSize = <span style="color:Blue; True
<span style="color:Blue; Me.autozoomButton.Checked = <span style="color:Blue; True
<span style="color:Blue; Me.autozoomButton.Location = <span style="color:Blue; New System.Drawing.Point(3, 3)
<span style="color:Blue; Me.autozoomButton.Name = <span style="color:#A31515; "autozoomButton"
<span style="color:Blue; Me.autozoomButton.Size = <span style="color:Blue; New System.Drawing.Size(74, 17)
<span style="color:Blue; Me.autozoomButton.TabIndex = 4
<span style="color:Blue; Me.autozoomButton.TabStop = <span style="color:Blue; True
<span style="color:Blue; Me.autozoomButton.Text = <span style="color:#A31515; "AutoZoom"
<span style="color:Blue; Me.autozoomButton.UseVisualStyleBackColor = <span style="color:Blue; True
<span style="color:Green;
<span style="color:Green; TableLayoutPanel1
<span style="color:Green;
<span style="color:Blue; Me.TableLayoutPanel1.ColumnCount = 2
<span style="color:Blue; Me.TableLayoutPanel1.ColumnStyles.Add(<span style="color:Blue; New System.Windows.Forms.ColumnStyle())
<span style="color:Blue; Me.TableLayoutPanel1.ColumnStyles.Add(<span style="color:Blue; New System.Windows.Forms.ColumnStyle())
<span style="color:Blue; Me.TableLayoutPanel1.Controls.Add(<span style="color:Blue; Me.FlowLayoutPanel2, 0, 1)
<span style="color:Blue; Me.TableLayoutPanel1.Controls.Add(<span style="color:Blue; Me.PictureBox1, 0, 0)
<span style="color:Blue; Me.TableLayoutPanel1.Controls.Add(<span style="color:Blue; Me.FlowLayoutPanel1, 1, 1)
<span style="color:Blue; Me.TableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill
<span style="color:Blue; Me.TableLayoutPanel1.Location = <span style="color:Blue; New System.Drawing.Point(0, 0)
<span style="color:Blue; Me.TableLayoutPanel1.Name = <span style="color:#A31515; "TableLayoutPanel1"
<span style="color:Blue; Me.TableLayoutPanel1.RowCount = 2
<span style="color:Blue; Me.TableLayoutPanel1.RowStyles.Add(<span style="color:Blue; New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100.0!))
<span style="color:Blue; Me.TableLayoutPanel1.RowStyles.Add(<span style="color:Blue; New System.Windows.Forms.RowStyle())
<span style="color:Blue; Me.TableLayoutPanel1.Size = <span style="color:Blue; New System.Drawing.Size(665, 311)
<span style="color:Blue; Me.TableLayoutPanel1.TabIndex = 4
<span style="color:Green;
<span style="color:Green; Form1
<span style="color:Green;
<span style="color:Blue; Me.AcceptButton = <span style="color:Blue; Me.showButton
<span style="color:Blue; Me.AutoScaleDimensions = <span style="color:Blue; New System.Drawing.SizeF(6.0!, 13.0!)
<span style="color:Blue; Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
<span style="color:Blue; Me.CancelButton = <span style="color:Blue; Me.closeButton
<span style="color:Blue; Me.ClientSize = <span style="color:Blue; New System.Drawing.Size(665, 311)
<span style="color:Blue; Me.Controls.Add(<span style="color:Blue; Me.TableLayoutPanel1)
<span style="color:Blue; Me.MinimumSize = <span style="color:Blue; New System.Drawing.Size(681, 100)
<span style="color:Blue; Me.Name = <span style="color:#A31515; "Form1"
<span style="color:Blue; Me.Text = <span style="color:#A31515; "Picture Viewer"
<span style="color:Blue; CType(<span style="color:Blue; Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
<span style="color:Blue; Me.FlowLayoutPanel1.ResumeLayout(<span style="color:Blue; False)
<span style="color:Blue; Me.FlowLayoutPanel1.PerformLayout()
<span style="color:Blue; Me.FlowLayoutPanel2.ResumeLayout(<span style="color:Blue; False)
<span style="color:Blue; Me.FlowLayoutPanel2.PerformLayout()
<span style="color:Blue; Me.TableLayoutPanel1.ResumeLayout(<span style="color:Blue; False)
<span style="color:Blue; Me.ResumeLayout(<span style="color:Blue; False)
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Friend <span style="color:Blue; WithEvents OpenFileDialog1 <span style="color:Blue; As System.Windows.Forms.OpenFileDialog
<span style="color:Blue; Friend <span style="color:Blue; WithEvents ColorDialog1 <span style="color:Blue; As System.Windows.Forms.ColorDialog
<span style="color:Blue; Friend <span style="color:Blue; WithEvents PictureBox1 <span style="color:Blue; As System.Windows.Forms.PictureBox
<span style="color:Blue; Friend <span style="color:Blue; WithEvents TableLayoutPanel1 <span style="color:Blue; As System.Windows.Forms.TableLayoutPanel
<span style="color:Blue; Friend <span style="color:Blue; WithEvents FlowLayoutPanel2 <span style="color:Blue; As System.Windows.Forms.FlowLayoutPanel
<span style="color:Blue; Friend <span style="color:Blue; WithEvents autozoomButton <span style="color:Blue; As System.Windows.Forms.RadioButton
<span style="color:Blue; Friend <span style="color:Blue; WithEvents normalButton <span style="color:Blue; As System.Windows.Forms.RadioButton
<span style="color:Blue; Friend <span style="color:Blue; WithEvents stretchButton <span style="color:Blue; As System.Windows.Forms.RadioButton
<span style="color:Blue; Friend <span style="color:Blue; WithEvents FlowLayoutPanel1 <span style="color:Blue; As System.Windows.Forms.FlowLayoutPanel
<span style="color:Blue; Friend <span style="color:Blue; WithEvents showButton <span style="color:Blue; As System.Windows.Forms.Button
<span style="color:Blue; Friend <span style="color:Blue; WithEvents clearButton <span style="color:Blue; As System.Windows.Forms.Button
<span style="color:Blue; Friend <span style="color:Blue; WithEvents backgroundButton <span style="color:Blue; As System.Windows.Forms.Button
<span style="color:Blue; Friend <span style="color:Blue; WithEvents closeButton <span style="color:Blue; As System.Windows.Forms.Button
<span style="color:Blue; End <span style="color:Blue; Class
[/code]
[/code]
View the full article