EDN Admin
Well-known member
I was wondering how to make this first sub do what I explain in the code. If you read the you will see what i am trying to do but its not working for me. :/
I tried using an if command but I think I screwed it up?
Here is the code and expanations, any help greatly appreciated. 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 dont 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
View the full article
I tried using an if command but I think I screwed it up?
Here is the code and expanations, any help greatly appreciated. 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 dont 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
View the full article