Public Class Form1
Dim kmx As Single, kmy As Single
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
Panel1.AutoScroll = True
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
Dim g As Graphics
Dim bmp As Bitmap
Dim i As Integer = 0
My.Application.DoEvents()
bmp = New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
g = Graphics.FromImage(bmp)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height))
g.Dispose()
Panel1.AutoScrollPosition = New Point(0, 0)
PictureBox1.Top = 0
PictureBox1.Left = 0
PictureBox1.Width = bmp.Width
PictureBox1.Height = bmp.Height
PictureBox1.Image = bmp
If Panel1.HorizontalScroll.Visible Or Panel1.VerticalScroll.Visible Then PictureBox1.Cursor = New Cursor("move.cur") Else PictureBox1.Cursor = Cursors.Default
End Sub
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
Panel1.AutoScrollPosition = New Point(0, 0)
PictureBox1.Top = 0
PictureBox1.Left = 0
PictureBox1.Width = My.Computer.Clipboard.GetImage.Width
PictureBox1.Height = My.Computer.Clipboard.GetImage.Height
PictureBox1.Image = My.Computer.Clipboard.GetImage
If Panel1.HorizontalScroll.Visible Or Panel1.VerticalScroll.Visible Then PictureBox1.Cursor = New Cursor("move.cur") Else PictureBox1.Cursor = Cursors.Default
End Sub
Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim newImage As Image
newImage = Image.FromFile(OpenFileDialog1.FileName)
Panel1.AutoScrollPosition = New Point(0, 0)
PictureBox1.Top = 0
PictureBox1.Left = 0
PictureBox1.Width = newImage.Width
PictureBox1.Height = newImage.Height
PictureBox1.Image = newImage
If Panel1.HorizontalScroll.Visible Or Panel1.VerticalScroll.Visible Then PictureBox1.Cursor = New Cursor("move.cur") Else PictureBox1.Cursor = Cursors.Default
End If
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If Panel1.HorizontalScroll.Visible Or Panel1.VerticalScroll.Visible Then
PictureBox1.Cursor = New Cursor("movekd.cur")
kmx = e.Location.X
kmy = e.Location.Y
PictureBox1.Tag = 1
End If
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
If Panel1.HorizontalScroll.Visible Or Panel1.VerticalScroll.Visible Then
PictureBox1.Cursor = New Cursor("move.cur")
PictureBox1.Tag = 0
End If
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If PictureBox1.Tag = 1 Then Panel1.AutoScrollPosition = New Point(Panel1.HorizontalScroll.Value + kmx - e.Location.X, Panel1.VerticalScroll.Value + kmy - e.Location.Y)
End Sub
Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PictureBox1.Image.Save(SaveFileDialog1.FileName)
End If
End Sub
End Class
|