Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class frmCapture
- Dim Screenshot As Bitmap
- Dim StartPoint As Point
- Dim EndPoint As Point
- Dim CapRect As Rectangle
- Private Sub frmCapture_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
- Me.Visible = False
- Dim Scr As Rectangle = Screen.PrimaryScreen.Bounds
- Screenshot = New Bitmap(Scr.Width, Scr.Height)
- Dim G As Graphics = Graphics.FromImage(Screenshot)
- G.CopyFromScreen(Scr.X, Scr.Y, 0, 0, Scr.Size)
- Me.BackgroundImage = Screenshot
- Me.Show()
- End Sub
- Private Sub frmCapture_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
- StartPoint = e.Location
- End Sub
- Private Sub frmCapture_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
- If e.Button = Windows.Forms.MouseButtons.Left Then
- EndPoint = e.Location
- End If
- If Not StartPoint.IsEmpty And Not EndPoint.IsEmpty Then
- CapRect.Location = New Point(0, 0)
- If EndPoint.X > StartPoint.X Then
- CapRect.Width = EndPoint.X - StartPoint.X
- CapRect.Location = New Point(StartPoint.X, CapRect.Location.Y)
- ElseIf EndPoint.X < StartPoint.X Then
- CapRect.Width = StartPoint.X - EndPoint.X
- CapRect.Location = New Point(EndPoint.X, CapRect.Location.Y)
- End If
- If EndPoint.Y > StartPoint.Y Then
- CapRect.Height = EndPoint.Y - StartPoint.Y
- CapRect.Location = New Point(CapRect.Location.X, StartPoint.Y)
- ElseIf EndPoint.Y < StartPoint.Y Then
- CapRect.Height = StartPoint.Y - EndPoint.Y
- CapRect.Location = New Point(CapRect.Location.X, EndPoint.Y)
- End If
- Invalidate()
- End If
- End Sub
- Private Sub frmCapture_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
- Me.Close()
- End Sub
- Private Sub frmCapture_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
- If EndPoint.IsEmpty Or StartPoint.IsEmpty Then Exit Sub
- Dim G As Graphics = e.Graphics
- G.FillRectangle(New SolidBrush(Color.FromArgb(70, Color.Silver)), CapRect)
- G.DrawRectangle(Pens.Silver, CapRect)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment