Page 1 of 1

Screen Caputre code not working

Posted: Mon Nov 19, 2012 9:50 pm
by muttley1968
Hello well basically i want to take a screen print of a panel and its contents and apply this to a picturebox after searching the web i have built this out of code i learnt from the web but well my edit seems to have messed things up it takes a picutre of were the panel was on form load but does not take it when the form moves or of the hole panel only a small cornoer of it

So here is the code i am using
Code: Select all
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim b As Bitmap
        b = New Bitmap(Panel3.Width, Panel3.Height, Imaging.PixelFormat.Format32bppArgb)
        Dim g As Graphics = Graphics.FromImage(b)
        g.CopyFromScreen(Panel3.Location, Panel3.Location, New Size(Panel3.Width, Panel3.Height))
        PictureBox3.SizeMode = PictureBoxSizeMode.StretchImage
        PictureBox3.Image = b
    End Sub

Re: Screen Caputre code not working

Posted: Mon Nov 19, 2012 10:07 pm
by mandai
It would be more reliable to use Panel.DrawToBitmap rather than Graphics.CopyFromScreen. In that code Panel3.Location is not a relative position for the screenshot.
basically i want to take a screen print of a panel and its contents
You can use this:
Code: Select all
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim b As Bitmap = New Bitmap(Panel3.Width, Panel3.Height, Imaging.PixelFormat.Format32bppArgb)
        Panel3.DrawToBitmap(b, New Rectangle(New Point(0, 0), b.Size))

        PictureBox3.SizeMode = PictureBoxSizeMode.StretchImage
        PictureBox3.Image = b

    End Sub

Re: Screen Caputre code not working

Posted: Mon Nov 19, 2012 10:46 pm
by muttley1968
that works Great Thank you very mutch