Question

I created a screen capture tool in vb.net 2010 using following code:

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    Dim snappit As String = 0
    TextBox1.Text -= snappit + 1
    If TextBox1.Text = 0 Then
        Me.Hide()
    End If
    If TextBox1.Text = -2 Then
        Try
            Dim screenshot 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), screenshot)

            screengrab.Save("snap.jpg")


            MsgBox("your screen has been snapped and the snap was saved", MsgBoxStyle.Information, "ScreenShot")
            Me.Show()
            Timer2.Stop()
            TextBox1.Text = 3
        Catch ex As Exception
            MsgBox("sorry unable to snap your screen and save at the moment please try again later", MsgBoxStyle.Critical, "Warning!")
        End Try
    End If
End Sub

This code store snap.jpg file in application path but i want to store it and in My Document/Screenshot

so i use

Dim SnapDir As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Screenshot\" 

is and try to move that jpg file in to snapdir but can't sucess...

so how to save that jpg file in snapdir or how to save that jpg file in dir using SaveFileDialog...

Thanks

and sorry for bad english...

Était-ce utile?

La solution

  1. Added Imports System.Drawing.Imaging

  2. Declare SnapDir as String

    Dim SnapDir As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Screenshot"
    
  3. Remove the trailing \ from "\Screenshot\". Add "& ".jpg")" to screengrab.Save(SnapDir)

  4. Took some of your code out, and plugged into a Command Button

    Dim SnapDir As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Screenshot"
    'Try
    Dim screenshot 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), screenshot)
    
    MsgBox(SnapDir & "snap.jpg")  'ADDED TO SHOW DIR
    screengrab.Save(SnapDir & ".jpg") 'ADDED & ".jpg")
    
    MsgBox("your screen has been snapped and the snap was saved", MsgBoxStyle.Information, "ScreenShot")
    Me.Show()
    

(screenshot taken with this code found in Libraries\Documents)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top