EDN Admin
Well-known member
I have this code working fine , it takes pictures of the correct size and correct file name , however , all the pictures it takes are in the top left corner of the screen , rather than where i have the form to.
FYI the picture box in the middle has no picture in it , and is transparent , i want to save a bitmap of the contents of the picturebox ( a user defined size of the screen). The picture box and button are docked so that the form scales properly when being
resized.
<pre>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br/><br/>Dim width As Integer = PictureBox1.Width
Dim height As Integer = PictureBox1.Height
Dim filename As String
filename = InputBox("Enter File Name (excluding file ending)")
filename = filename + ".bmp"
Dim image As New Bitmap(width, height)
Dim g As Graphics = Graphics.FromImage(image)
g.CopyFromScreen(PictureBox1.Location.X, PictureBox1.Location.Y, PictureBox1.Location.X, PictureBox1.Location.Y, image.Size)
g.Dispose()
image.Save(filename)
MessageBox.Show("File " + filename + " has been saved")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TopMost = True
End Sub
End Class[/code]
Thanks for any help.
View the full article
FYI the picture box in the middle has no picture in it , and is transparent , i want to save a bitmap of the contents of the picturebox ( a user defined size of the screen). The picture box and button are docked so that the form scales properly when being
resized.
<pre>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br/><br/>Dim width As Integer = PictureBox1.Width
Dim height As Integer = PictureBox1.Height
Dim filename As String
filename = InputBox("Enter File Name (excluding file ending)")
filename = filename + ".bmp"
Dim image As New Bitmap(width, height)
Dim g As Graphics = Graphics.FromImage(image)
g.CopyFromScreen(PictureBox1.Location.X, PictureBox1.Location.Y, PictureBox1.Location.X, PictureBox1.Location.Y, image.Size)
g.Dispose()
image.Save(filename)
MessageBox.Show("File " + filename + " has been saved")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TopMost = True
End Sub
End Class[/code]
Thanks for any help.
View the full article