Screen Caputre code not working

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
3 posts Page 1 of 1
Contributors
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Screen Caputre code not working
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
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Screen Caputre code not working
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
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

that works Great Thank you very mutch
3 posts Page 1 of 1
Return to “Coding Help & Support”