Skip to main content

VB.NET
Taking & Saving Screenshots (Part 1)

Form1.vb

' AZUL CODING ---------------------------------------
' VB.NET - Taking & Saving Screenshots (Part 1)
' https://youtu.be/pr7MEcmCHwM


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    If Not NumericUpDown1.Value = 0 Then
        Timer1.Interval = NumericUpDown1.Value * 1000

    Else
        Timer1.Interval = 100

    End If

    Text = "Loading..."
    Enabled = False

    Timer1.Start()

End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Dim ScreenCapture As Bitmap
    Dim graph As Graphics

    ScreenCapture = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Imaging.PixelFormat.Format32bppArgb)
    graph = Graphics.FromImage(ScreenCapture)
    graph.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)

    PictureBox1.BackgroundImage = ScreenCapture

    Text = "Screenshot"
    Enabled = True

    Timer1.Stop()

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    PictureBox1.BackgroundImage.Save(My.Computer.FileSystem.SpecialDirectories.MyPictures + "\Screenshots\filename.png")

End Sub

Enjoying this tutorial?