Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click
'create the bitmap and graphics objects
Dim b As Bitmap = New Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height)
Dim g As Graphics = Graphics.FromImage(b)
Dim s As Size = New Sizе(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height)
'copy the image form the screen. You can customize the size 'and postions to take the screenshot from
g.CopyFromScreen(0, 0, 0, 0, s, CopyPixelOperation.SourceCopy)
'load the copied image to the picturebox control
pic.Image = b
'clean up alittle
g.Dispose()
b = Nothing
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
'dim new saveDialog and dialogResult objects
Dim saveDlg As SaveFileDialog = New SaveFileDialog
Dim dlgResult As DialogResult = New DialogResult
'set the filter to JPEG files only
saveDlg.Filter = "JPEG Files (*.jpg)|*.jpg"
saveDlg.Title = "Determine the file to save the image too"
dlgResult = saveDlg.ShowDialog
If dlgResult = Windows.Forms.DialogResult.OK Then
'save the image contained in the picturebox
pic.Image.Save(saveDlg.FileName)