MikeMCSD
asked on
PrintDocument problem
I have a PrintDocument control that is printing my Desktop instead of the form.
Here is an excerpt of the code:
Dim nullObject As System.Object = 0
Dim str As String = ""
Dim nullObjStr As System.Object = str
....
AxWebBrowser1.Navigate("http://www.MySite.com/Report.aspx?OrderID=" & spParam , nullObject, nullObjStr, nullObjStr, nullObjStr)
CaptureScreen()
PrintDocument1.PrinterSett ings.Print erName = _prtNameInkJ
PrintDocument1.Print()
........
Private Declare Function BitBlt Lib "gdi32.dll" Alias "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 Long
Dim memoryImage As Bitmap
Private Sub CaptureScreen()
Dim mygraphics As Graphics = Me.CreateGraphics()
Dim s As Size = Me.Size
memoryImage = New Bitmap(s.Width, s.Height, mygraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryI mage)
Dim dc1 As IntPtr = mygraphics.GetHdc
Dim dc2 As IntPtr = memoryGraphics.GetHdc
BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height, dc1, 0, 0, 13369376)
mygraphics.ReleaseHdc(dc1)
memoryGraphics.ReleaseHdc( dc2)
End Sub
Private Sub PrintDocument1_PrintPage(B yVal sender As System.Object, ByVal e As System.Drawing.Printing.Pr intPageEve ntArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawImage(memor yImage, 0, 0)
End Sub
But it does show the www.MySite.com in the Web browser control.
Here is an excerpt of the code:
Dim nullObject As System.Object = 0
Dim str As String = ""
Dim nullObjStr As System.Object = str
....
AxWebBrowser1.Navigate("http://www.MySite.com/Report.aspx?OrderID=" & spParam , nullObject, nullObjStr, nullObjStr, nullObjStr)
CaptureScreen()
PrintDocument1.PrinterSett
PrintDocument1.Print()
........
Private Declare Function BitBlt Lib "gdi32.dll" Alias "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 Long
Dim memoryImage As Bitmap
Private Sub CaptureScreen()
Dim mygraphics As Graphics = Me.CreateGraphics()
Dim s As Size = Me.Size
memoryImage = New Bitmap(s.Width, s.Height, mygraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryI
Dim dc1 As IntPtr = mygraphics.GetHdc
Dim dc2 As IntPtr = memoryGraphics.GetHdc
BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height,
mygraphics.ReleaseHdc(dc1)
memoryGraphics.ReleaseHdc(
End Sub
Private Sub PrintDocument1_PrintPage(B
e.Graphics.DrawImage(memor
End Sub
But it does show the www.MySite.com in the Web browser control.
ASKER
YES!
ASKER
If I do this:
PrintPreviewDialog1.Docume nt = PrintDocument1
PrintPreviewDialog1.Show()
it shows a screen shot of the current window, Visual Studio.
PrintPreviewDialog1.Docume
PrintPreviewDialog1.Show()
it shows a screen shot of the current window, Visual Studio.
did you develop the web page? if so, you can add a button or link with javascript:window.print(); for the onclick event and it will print the page.
you could also screen scrape the web page...either method imho would be more efficient than getting a screenshot....
but, if you stick with the screenshot method....I wonder if it is because you are in debug mode that it returns the VS.net window?
like if you ran the final *.exe file it would give you your app's window instead of vs.net window...
you could also screen scrape the web page...either method imho would be more efficient than getting a screenshot....
but, if you stick with the screenshot method....I wonder if it is because you are in debug mode that it returns the VS.net window?
like if you ran the final *.exe file it would give you your app's window instead of vs.net window...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks sam . . I tried using <body onload="window.print();">
but it seems to just ignore it.
Let me look at the rolla thing.
but it seems to just ignore it.
Let me look at the rolla thing.
ASKER
mistake . . the <body onload="window.print();">
works . . but only prints the last document in the run (I have a loop) . .
and the "Print" dialog appears (for the last document)
works . . but only prints the last document in the run (I have a loop) . .
and the "Print" dialog appears (for the last document)
Is your goal to print the web page?