Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Scrollable form in .NET

Status
Not open for further replies.

saadabc

Programmer
Aug 5, 2004
107
0
0
US
Hi I'm using the following code to print the contents of a form in a Visual Basic .NET application.


Public SRCCOPY As Integer = &HCC0020

' BitBlt dwRop parameter
<DllImport("gdi32.dll")> _
Public Shared Function BitBlt(ByVal hObject As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hObjectSource As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As Integer) As Boolean
End Function



Private Sub btPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btPrint.Click

Application.DoEvents()
Me.Refresh()
Application.DoEvents()

CreateFormImage()

'Show the PrintDialog
PrintDocument1 = New PrintDocument
PrintDocument1.DefaultPageSettings.Landscape = True
PrintDialog1 = New PrintDialog
PrintDialog1.Document = PrintDocument1

Dim r As DialogResult = PrintDialog1.ShowDialog
AddHandler PrintDocument1.PrintPage, AddressOf printDocument1_PrintPage


If r = DialogResult.OK Then
'Print the document
PrintDocument1.Print()
End If

End Sub

Private Sub CreateFormImage()
'Get a Graphics Object from the form
Dim FormG As Graphics = Me.CreateGraphics

'Create a bitmap from that graphics
Dim i As New Bitmap(Me.Width, Me.Height, FormG)

'Create a Graphics object in memory from that bitmap
Dim memG As Graphics = Graphics.FromImage(i)

'get the IntPtr's of the graphics
Dim HDC1 As IntPtr = FormG.GetHdc
Dim HDC2 As IntPtr = memG.GetHdc

'get the picture
BitBlt(HDC2, 0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height, HDC1, 0, 0, 13369376)

'Clone the bitmap so we can dispose this one
Me.Print_Image = i.Clone()

'Clean Up
FormG.ReleaseHdc(HDC1)
memG.ReleaseHdc(HDC2)
FormG.Dispose()
memG.Dispose()
i.Dispose()

End Sub


Private Sub printDocument1_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)

e.Graphics.DrawImage(Me.Print_Image, 0, 0)

End sub

it's basically just using example from


my problem is that my form is a vertifically scrollable form - and there is information that is hidden below the visible area on the screen - and that information needs to be scrolled down to.. The code above is not capturing the hidden area of the form (the area that one has to scroll down to get to).


I tried adding the following lines:


'Scroll to a Control that is at the bottom of the second page of the form
Me.ScrollControlIntoView(txtMyControl)

'Recapture the image of the form
CreateFormImage()

PrintDocument1.Print()

But the CreateGraphics method still creates an image of the top area of the form (the area that we can call the First Page).

so - in effect, it just reprints the same page over.



Any solutions?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top