Question Bitmaps in memory?

ALX

Well-known member
Joined
Nov 16, 2005
Messages
253
Location
Columbia, SC
Programming Experience
10+
This may be a stupid question, but I'm fearless...

There is a form (let's say Form A) in my app that uses a reduced snapshot of a different form (Form B) in the same app. The way I've been doing this is:

1st- Display the form that I need to copy. (Form B)
2nd- Run through a quick "BitBlt" API call & save the image to a shared bitmap variable.
3rd- Display Form A and assign the bitmap to a picturebox in Form A
4th- Close Form B

This works OK. I was just wondering if there was a way that I could capture the image of Form B without actually displaying it to avoid the distraction of having Form B show briefly just before Form A is shown... say if there were a way to construct Form B in memory and then capture the image from there. It would appear a little more professionally constructed that way. Is this reasonably do-able?
 
Use the hidden form's DrawToBitmap method. For example, assuming Form1 is hidden:

VB.NET:
Dim bmp As New Bitmap(Form1.Width, Form1.Height)
Dim rect As New Rectangle(0, 0, Form1.Width, Form1.Height)
Form1.DrawToBitmap(bmp, rect)

DrawToBitmap always captures the whole form (as long as the bitmap is big enough) starting from the top left of the title bar. If you don't want that, set its FormBorderStyle to None before using DrawToBitmap.

bye, Vic
 
This is a great way (and a shorter way than I was using) to capture a bitmap of the screen. But unless I'm screwing up somewhere, it appears that I have to display the form 1st... which is what I was trying to avoid.

-Edited: Well it seems that I can show the form and then immediately hide it and then use your approach... So as far as the users' point of view goes, it never really appears. -(Barely a flash on the screen)- I guess it's a cheat, but it works for me! Thanks for your help!!!
 
Last edited:
Back
Top