Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
HScrollBar1.Maximum = PictureBox1.Image.Width - _
PictureBox1.Width + HScrollBar1.Height
VScrollBar1.Maximum = PictureBox1.Image.Height - _
PictureBox1.Height + VScrollBar1.Width
VScrollBar1.Enabled = True
HScrollBar1.Enabled = True
If PictureBox1.Height > PictureBox1.Image.Height Then
VScrollBar1.Enabled = False
End If
If PictureBox1.Width > PictureBox1.Image.Width Then
HScrollBar1.Enabled = False
End If
End If
End Sub
Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
Dim gph As Graphics = PictureBox1.CreateGraphics
gph.DrawImage(PictureBox1.Image, New Rectangle(0, 0, PictureBox1.Width - HScrollBar1.Height, _
PictureBox1.Height - VScrollBar1.Width), _
New Rectangle(HScrollBar1.Value, VScrollBar1.Value, _
PictureBox1.Width - HScrollBar1.Height, _
PictureBox1.Height - VScrollBar1.Width), GraphicsUnit.Pixel)
End Sub
Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
Dim gph As Graphics = PictureBox1.CreateGraphics
gph.DrawImage(PictureBox1.Image, New Rectangle(0, 0, PictureBox1.Width - HScrollBar1.Height, _
PictureBox1.Height - VScrollBar1.Width), _
New Rectangle(HScrollBar1.Value, VScrollBar1.Value, _
PictureBox1.Width - HScrollBar1.Height, _
PictureBox1.Height - VScrollBar1.Width), GraphicsUnit.Pixel)
End Sub