Results 1 to 9 of 9

Thread: panel screen shot

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    284

    panel screen shot

    I have a panel, how can I save a picture of what is visible in that panel to file as a bmp?
    I am still very new to VB.NET, so I have MANY questions

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: panel screen shot

    Try this:
    vb.net Code:
    1. Using bmp As New Bitmap(Me.Panel1.Width, Me.Panel1.Height)
    2.     Me.Panel1.DrawToBitmap(bmp, Me.Panel1.ClientRectangle)
    3.     bmp.Save("C:\test\panel.bmp", Imaging.ImageFormat.Bmp)
    4. End Using

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    284

    Re: panel screen shot

    close...

    That just draws that panel. the panel has 1+ picture boxes in it, and the provided code only draws that panel, and not the picture boxes inside of it.

    Help is appreciated!
    I am still very new to VB.NET, so I have MANY questions

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: panel screen shot

    ForumAccount's code actually does draw the child controls of the Panel. It's just that they are drawn off the visible area of the Bitmap because the second argument to DrawToBitmap is incorrect. The targetBounds is relative to the Bitmap being drawn on, not the form containing the control:
    vb.net Code:
    1. Using bmp As New Bitmap(Me.Panel1.Width, Me.Panel1.Height)
    2.     Me.Panel1.DrawToBitmap(bmp, New Rectangle(Point.Empty, bmp.Size))
    3.     bmp.Save("C:\test\panel.bmp", Imaging.ImageFormat.Bmp)
    4. End Using
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    284

    Re: panel screen shot

    OK! it works, but for some reason, when I put a picture box in, then place another on top of that one, it draws it reverse that...

    For example:

    Image A: 100x100
    Image B: 200x200

    If I first place "Image B" then paste "Image A" on top of that in the program it looks fine, but when I do the save, "Image B" is on top of "Image A" so "Image A" isn't visible.

    If I first place "Image A" then paste "Image B" on top of that in the program it does not look fine, but when I do the save, "Image A" is on top of "Image B" so Now it looks like it did in the previous paragraph.

    Why is it doing that?
    I am still very new to VB.NET, so I have MANY questions

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: panel screen shot

    Quote Originally Posted by The Little Guy View Post
    OK! it works, but for some reason, when I put a picture box in, then place another on top of that one, it draws it reverse that...

    For example:

    Image A: 100x100
    Image B: 200x200

    If I first place "Image B" then paste "Image A" on top of that in the program it looks fine, but when I do the save, "Image B" is on top of "Image A" so "Image A" isn't visible.

    If I first place "Image A" then paste "Image B" on top of that in the program it does not look fine, but when I do the save, "Image A" is on top of "Image B" so Now it looks like it did in the previous paragraph.

    Why is it doing that?
    I haven't tested that but it sounds like a bug. If so then, as a workaround, you could temporarily reverse the z-order of the child controls.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    284

    Re: panel screen shot

    What would be the best way to reverse them?
    I am still very new to VB.NET, so I have MANY questions

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: panel screen shot

    The order of the items in the Controls collection sets the z-order. You can use a loop and call SetChildIndex on the Controls collection or you can call BringToFront or SendToBack on the controls themselves. Just be aware that each time you make a change the order of the items in the collection will change, so you can't just loop as though they stay put. Think about it and experiment a bit and come up with some logic that will work. You don't even have to loop through the Controls collection itself. You can put all the controls into an array or collection first and loop through that. That way their positions in the list you're looping through won't change as they change in the Controls collection.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    284

    Re: panel screen shot

    Alright, I got it!

    If you have any solutions to this, please let me know!
    I am still very new to VB.NET, so I have MANY questions

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width