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("" & spParam , nullObject, nullObjStr, nullObjStr, nullObjStr)
       PrintDocument1.PrinterSettings.PrinterName = _prtNameInkJ

 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(memoryImage)
      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)
   End Sub

   Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
      e.Graphics.DrawImage(memoryImage, 0, 0)
   End Sub

But it does show the in the Web browser control.

LVL 16
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Is your goal to print the web page?
MikeMCSDAuthor Commented:
MikeMCSDAuthor Commented:
If I do this:
PrintPreviewDialog1.Document = PrintDocument1

it shows a screen shot of the current window, Visual Studio.
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

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 window?
like if you ran the final *.exe file it would give you your app's window instead of window...
screen scraping:

so the tute above lets you grab all the html off of the web into a string....if you mod the code so that the body tag includes someting like <body onload="javascript:window.print();">.....the page would automatically print....or mebbe find a different way to send the html string to the printer

just ideas!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MikeMCSDAuthor Commented:
thanks sam . . I tried using <body onload="window.print();">
but it seems to just ignore it.
Let me look at the rolla thing.

MikeMCSDAuthor Commented:
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)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.