Results 1 to 4 of 4

Thread: Printing From Form . . . [RESOLVED - all by meeself!]

  1. #1

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Resolved Printing From Form . . . [RESOLVED - all by meeself!]

    Ok...I'm getting close on this one, but there's something missing.

    I have a form that's using a WebBrowser control (thanks Matt and Rob) to pull up a local html page and it's (eventually) going to insert logos, data, etc. to print reports, shippers, invoices.

    Clicking on "Print..." in my menu brings up the usual print dialog correctly...clicking on "Print" in the print dialog brings up a message box that says "Printing Invoice - Page 1". So I'm pretty sure something's working up to that point, but I'm thinking no data is being sent to the printer.

    For the time being, I am using google in the page just to work on the print functionality, and the printer fidgets a little, so it's getting at least a handshake, but nothing ever happens, no paper is even pulled down.

    Here's what I have so far in my print code:
    VB Code:
    1. Private Sub InvoiceBrowser_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InvoiceBrowser.Enter
    2.         InvoiceBrowser.Navigate("http://www.google.com")
    3.     End Sub
    4.  
    5.     Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
    6. 'I'm missing something in here, I just know it.
    7.         PrintInvoiceDialog.ShowDialog()
    8.         PrintInvoice.Print()
    9.     End Sub
    10.  
    11.     Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
    12.         Me.Close()
    13.     End Sub
    What else do I need to get the thing to actually print?

    Thanks,
    CP
    Last edited by milkmood; May 13th, 2005 at 01:31 PM.

  2. #2

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Re: Printing From Form . . .

    I started using the sample in the 101 VB.NET samples, and it's pretty good, but it seems to only show how to use it with unformatted text. Since I'll be printing html pages with mine, what needs to be different?

    CP

  3. #3

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Re: Printing From Form . . .

    Anybody? Matt? Rob?

  4. #4

    Thread Starter
    Lively Member milkmood's Avatar
    Join Date
    Mar 2005
    Location
    Forests of Delta Halo
    Posts
    109

    Talking Re: Printing From Form . . .

    I found a great solution for this HERE . . . one line of code to print a web page from the AxWebBrowser control, in fact, here's my whole form code so far...
    VB Code:
    1. Imports System.IO
    2.  
    3.         'InvoiceBrowser is the name I gave the AxWebBrowser control on this page.  
    4.         'This code simply gets the html file and renders it like IE would, plug-ins and all.  
    5.         'I *do* need to add a catch in here if it can't find the base html file.
    6.     Private Sub InvoiceBrowser_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InvoiceBrowser.Enter
    7.         InvoiceBrowser.Navigate("C:\blah\blah\blah\invoice.htm")
    8.     End Sub
    9.  
    10.         'This is the print event itself.  
    11.         'It just uses the Javascript plug-in that *everybody* has in IE,
    12.         'I would think.
    13.     Private Sub mnuPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPrint.Click
    14.         InvoiceBrowser.Document.parentWindow.execScript("window.print();", "JScript")
    15.     End Sub
    16.  
    17.     Private Sub mnuClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClose.Click
    18.         Me.Close()
    19.     End Sub

    It doesn't give a print preview, but it DOES bring up the print dialog. It works exactly as if you right clicked on the web page and selected "Print".

    Awesome.

    CP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width