Guest User

frmCapture

a guest
Aug 18th, 2012
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.42 KB | None | 0 0
  1. Public Class frmCapture
  2.  
  3.     Dim Screenshot As Bitmap
  4.     Dim StartPoint As Point
  5.     Dim EndPoint As Point
  6.     Dim CapRect As Rectangle
  7.  
  8.     Private Sub frmCapture_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  9.         Me.Visible = False
  10.         Dim Scr As Rectangle = Screen.PrimaryScreen.Bounds
  11.         Screenshot = New Bitmap(Scr.Width, Scr.Height)
  12.         Dim G As Graphics = Graphics.FromImage(Screenshot)
  13.         G.CopyFromScreen(Scr.X, Scr.Y, 0, 0, Scr.Size)
  14.         Me.BackgroundImage = Screenshot
  15.         Me.Show()
  16.     End Sub
  17.  
  18.     Private Sub frmCapture_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
  19.         StartPoint = e.Location
  20.     End Sub
  21.  
  22.     Private Sub frmCapture_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
  23.         If e.Button = Windows.Forms.MouseButtons.Left Then
  24.             EndPoint = e.Location
  25.         End If
  26.  
  27.         If Not StartPoint.IsEmpty And Not EndPoint.IsEmpty Then
  28.             CapRect.Location = New Point(0, 0)
  29.             If EndPoint.X > StartPoint.X Then
  30.                 CapRect.Width = EndPoint.X - StartPoint.X
  31.                 CapRect.Location = New Point(StartPoint.X, CapRect.Location.Y)
  32.             ElseIf EndPoint.X < StartPoint.X Then
  33.                 CapRect.Width = StartPoint.X - EndPoint.X
  34.                 CapRect.Location = New Point(EndPoint.X, CapRect.Location.Y)
  35.             End If
  36.  
  37.             If EndPoint.Y > StartPoint.Y Then
  38.                 CapRect.Height = EndPoint.Y - StartPoint.Y
  39.                 CapRect.Location = New Point(CapRect.Location.X, StartPoint.Y)
  40.             ElseIf EndPoint.Y < StartPoint.Y Then
  41.                 CapRect.Height = StartPoint.Y - EndPoint.Y
  42.                 CapRect.Location = New Point(CapRect.Location.X, EndPoint.Y)
  43.             End If
  44.             Invalidate()
  45.         End If
  46.     End Sub
  47.  
  48.     Private Sub frmCapture_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
  49.         Me.Close()
  50.     End Sub
  51.  
  52.     Private Sub frmCapture_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
  53.         If EndPoint.IsEmpty Or StartPoint.IsEmpty Then Exit Sub
  54.         Dim G As Graphics = e.Graphics
  55.         G.FillRectangle(New SolidBrush(Color.FromArgb(70, Color.Silver)), CapRect)
  56.         G.DrawRectangle(Pens.Silver, CapRect)
  57.     End Sub
  58.  
  59. End Class
Advertisement
Add Comment
Please, Sign In to add comment