Oh the word wrap messes it all up!
This is word-wrap safe
-------------------------CODE STARTS--------------------------------
Dim img As Bitmap
Dim WithEvents pd As Printing.PrintDocument
'-1- API CALL TO BITBLT
'Function to convert the form to an image
Function CaptureForm1() As Bitmap
Dim g1 As Graphics = Me.CreateGraphics()
Dim MyImage = New Bitmap(Me.ClientRectangle.Width, _
(Me.ClientRectangle.Height), g1)
Dim g2 As Graphics = Graphics.FromImage(MyImage)
Dim dc1 As IntPtr = g1.GetHdc()
Dim dc2 As IntPtr = g2.GetHdc()
'BitBlt is an API Call as defined above at -1-
BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, _
(Me.ClientRectangle.Height), dc1, 0, 0, 13369376)
g1.ReleaseHdc(dc1)
g2.ReleaseHdc(dc2)
Return MyImage
End Function
<Runtime.InteropServices.DllImport("gdi32.DLL", _
EntryPoint:="BitBlt", SetLastError:=True, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall)> _
Private Shared Function BitBlt(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
End Function
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
img = CaptureForm1()
pd = New Printing.PrintDocument
'Page is sent to the default printer for printing
'Use Printing.PrinterSettings object to customize the print behavior
pd.Print()
End Sub
Sub pd_PrintPage(ByVal sender As Object, _
ByVal e As Printing.PrintPageEventArgs) Handles pd.PrintPage
Dim x As Integer = e.MarginBounds.X
Dim y As Integer = e.MarginBounds.Y
e.Graphics.DrawImage(img, x, y)
e.HasMorePages = False
End Sub
---------------------------CODE ENDS---------------------------------
-Rajneesh