save to different file name?

marsmela

New member
Joined
Feb 18, 2010
Messages
1
Programming Experience
Beginner
First sorry for my bad english !

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ScreenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
        Dim screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
        Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenGrab)
        g.CopyFromScreen(New Point(0, 0), New Point(0, 0), ScreenSize)
        'screenGrab.Save("C:\screenGrab.bmp")
        screenGrab.Save("C:\JPEGscreen.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

1# This is mi Screen Shooter !! I need Button1 on key Press but i dont know command.

2# screenGrab.Save("C:\JPEGscreen.jpg" - The picture still saving as "JPEGscreen.jpg" New file will replace old ... I want random generate image name , save by date or something else

Thx a lot .. mx
 
To get the following to work you will need to make sure that the KeyPreview of the form is set to True. The KeyDown method will do a screenshot every time the 'P' key is pressed.

Incidentally, if you had searched the this forum for "keypress" then you would have found several posts that would have helped you out.

VB.NET:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

        If e.KeyCode = Keys.P Then
            ScreenGrabMethod()
        End If

    End Sub

    Private Sub ScreenGrabMethod()

        Dim ScreenSize As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
        Dim screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
        Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenGrab)
        g.CopyFromScreen(New Point(0, 0), New Point(0, 0), ScreenSize)

        Dim ScreenGrabFileName As String = (Now.ToString("MMddyyyyhhmmssffff") & "ScreenGrab.jpg")

        'Dim ScreenGrabFileName As String = Guid.NewGuid().ToString().Replace("-", "").ToUpper() & ".jpg"

        screenGrab.Save(My.Computer.FileSystem.CombinePath("C:\", ScreenGrabFileName), System.Drawing.Imaging.ImageFormat.Jpeg)

    End Sub

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

        ScreenGrabMethod()

    End Sub
 
Back
Top