Save Form as a bitmap


Active member
Dec 4, 2004
Programming Experience
i have a dynamic form on which i draw different labels and images based on the values in my db (basically a report) its length is also unknown (screenshot attached). Please tell me if there is any way i can save this form as an image on my hard drive.
I basically have to print this report but cant find any way of doing it so thought of saving it as an image n then printing it


  • myReport.gif
    23.8 KB · Views: 100
If you create it as 1 large image you can use the save function that's built into the bitmap class, you can even save it as different file types (.Jpg .Gif etc)

I thought you had sorted the printing out?
I believe that you want something like this. The following code will take a screenshot of the form as an image, then use that image on a PrintPreview Control. You can then print it from there.

I believe that this will only work if the form/image is about the size of one printed page

' API call to help generate final screenshot
	Private Declare Auto Function BitBlt Lib "gdi32.dll" (ByVal hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As System.Int32) As Boolean

	' Variable to store screenshot
	Private bmpScreenshot As Bitmap

Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click, mnuFilePreview.Click


			PrintPreviewDialog1.Document = Me.PrintDocument1
		Catch es As Exception
		End Try

	End Sub

	Private Sub GrabScreen()
		' Performs a screenshot, saving results to bmpScreenshot
		Dim objGraphics As Graphics = Me.CreateGraphics
		Dim objSize As Size = Me.Size
		Const SRCCOPY As Integer = &HCC0020

		bmpScreenshot = New Bitmap(objSize.Width, objSize.Height, _
		Dim objGraphics2 As Graphics = _
		Dim deviceContext1 As IntPtr = objGraphics.GetHdc
		Dim deviceContext2 As IntPtr = objGraphics2.GetHdc

		BitBlt(deviceContext2, 0, 0, Me.ClientRectangle.Width, _
		  Me.ClientRectangle.Height, deviceContext1, 0, 0, SRCCOPY)
	End Sub

	Private Sub MyPrintDocument_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
		' Method that handles the printing
		Dim objImageToPrint As Graphics = e.Graphics
		objImageToPrint.DrawImage(bmpScreenshot, 0, 0)
		e.HasMorePages = False
	End Sub