How to Capture Full Screen using VB.Net

0
83

This Tutorial is all about How to Capture Full Screen using VB.Net. In this tutorial you will be able to Capture Full Screen using VB.Net So lets get Started:

  • First is open the Visual Basic, Select File on the menu, then click New and create a new project.

  • Then a New Project Dialog will appear. You can rename your project, depending on what you like to name it. After that click OK

  • After that, design your form like this just like what I’ve shown you below.
    Add a Picturebox, Button and a Timer.
    Change the PictureBox SizeMode property to Zoom.
    Change the Timer Enabled property to True and change Interval to 1000.
  • Then add this following Declarations.
    1. Public Shared Image As Image
    2. Public Shared Bounds As Rectangle
    3. Public Shared TimerCount As Integer
  • Also add this following Functions.
    1. Shared Function GetDesktopImage(Optional ByVal Width As Integer = 0, Optional ByVal Height As Integer = 0, Optional ByVal ShowCursor As Boolean = True) As Image
    2. Dim W As Integer = Screen.PrimaryScreen.Bounds.Width
    3. Dim H As Integer = Screen.PrimaryScreen.Bounds.Height
    4. Dim DesktopBitmap As New Bitmap(W, H)
    5. Dim g As Graphics = Graphics.FromImage(DesktopBitmap)
    6. g.CopyFromScreen(0, 0, 0, 0, New Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height), CopyPixelOperation.SourceCopy)
    7. If ShowCursor Then Cursors.Default.Draw(g, New Rectangle(Cursor.Position, New Size(32, 32)))
    8. g.Dispose()
    9. If Width = 0 And Height = 0 Then
    10. Image = DesktopBitmap
    11. Return DesktopBitmapElse
    12. Dim ScaledBitmap As Image = DesktopBitmap.GetThumbnailImage(Width, Height, Nothing, IntPtr.Zero)
    13. DesktopBitmap.Dispose()
    14. Image = ScaledBitmap
    15. Return ScaledBitmap
    16. End If
    17. End Function
  • Add this code to the timer.
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2. TimerCount += 1If TimerCount = 1 And Me.WindowState = FormWindowState.Minimized Then
    3. PictureBox1.Image = GetDesktopImage()
    4.  
    5. End If
    6. If TimerCount = 2 And Me.WindowState = FormWindowState.Minimized Then
    7. Me.WindowState = FormWindowState.Normal
    8. End If
    9. End Sub
  • Add this code to the button.
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2. Me.WindowState = FormWindowState.Minimized
    3. TimerCount = 0
    4. End Sub
  • Finally, Click F5 to run the Program.

Output:

If you have any comments or suggestions about on How to Capture Full Screen using VB.Net, please feel free to contact our webpage.

Download How to Capture Full Screen using VB.Net Here

Other Articles Readers might read:

 

Facebook Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here