|
-
Aug 17th, 2009, 06:48 PM
#1
Thread Starter
Hyperactive Member
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
-
Aug 17th, 2009, 07:11 PM
#2
Re: panel screen shot
Try this:
vb.net Code:
Using bmp As New Bitmap(Me.Panel1.Width, Me.Panel1.Height) Me.Panel1.DrawToBitmap(bmp, Me.Panel1.ClientRectangle) bmp.Save("C:\test\panel.bmp", Imaging.ImageFormat.Bmp) End Using
-
Aug 17th, 2009, 08:23 PM
#3
Thread Starter
Hyperactive Member
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
-
Aug 18th, 2009, 03:35 AM
#4
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:
Using bmp As New Bitmap(Me.Panel1.Width, Me.Panel1.Height) Me.Panel1.DrawToBitmap(bmp, New Rectangle(Point.Empty, bmp.Size)) bmp.Save("C:\test\panel.bmp", Imaging.ImageFormat.Bmp) End Using
-
Aug 18th, 2009, 04:01 AM
#5
Thread Starter
Hyperactive Member
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
-
Aug 18th, 2009, 05:59 AM
#6
Re: panel screen shot
 Originally Posted by The Little Guy
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.
-
Aug 19th, 2009, 01:17 AM
#7
Thread Starter
Hyperactive Member
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
-
Aug 19th, 2009, 01:24 AM
#8
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.
-
Aug 19th, 2009, 02:13 AM
#9
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|