Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42466

VS 2012 Can someone help me get this Screenshot form working

$
0
0
I have explained how i want to get this working in the code but i am stuck and need someone to help me with the code to get this to the way i want it, you will make my day if you can help

Code:

'TakeScreenshot is a button which will capture the current window.
'I am using key-press as a bind, but I need to be able to activate the key-bind while the
'form window is minimized or hidden while the screenshot is taken place.
Public Class TakeScreenshot
    Private Sub takeScreenButton_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles takeScreenButton.KeyPress
        'I tried using this if statement which stopped the whole thing from working.
        If e.KeyChar = Chr(13) Then

            ' Do hide buttons so they don't appear in the screenshot.
            takeScreenButton.Hide()
            savescreenButton.Hide()
            Me.Hide()
        End If

        'What i am trying to do here is hide the form taking the screenshot so that I can capture
        'the window behind the form, otherwise the form window will be in the screenshot and i dont want that.
        '===========================================
        'The below is how the picture gets taken...
        Dim bounds As Rectangle
        Dim screenshot As System.Drawing.Bitmap
        Dim graph As Graphics
        bounds = Screen.PrimaryScreen.Bounds
        screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
        graph = Graphics.FromImage(screenshot)
        graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
        PictureBox1.Image = screenshot

        savescreenButton.Show()
    End Sub

    'This below sub is fine, as i have something worked out for this part. ;)

    Private Sub savescreenButton_Click(sender As Object, e As EventArgs) Handles savescreenButton.Click
        Dim savefiledialog1 As New SaveFileDialog
        Try
            savefiledialog1.Title = "Save File"
            savefiledialog1.FileName = "*.jpg"
            savefiledialog1.Filter = "JPEG |*.jpg"
            If savefiledialog1.ShowDialog() = DialogResult.OK Then
                PictureBox1.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
            End If
        Catch ex As Exception 'Do Nothing
        End Try
    End Sub

    Private Sub TakeScreenshot_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class


Viewing all articles
Browse latest Browse all 42466

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>