|
-
May 12th, 2005, 01:06 PM
#1
Thread Starter
Lively Member
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:
Private Sub InvoiceBrowser_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InvoiceBrowser.Enter
InvoiceBrowser.Navigate("http://www.google.com")
End Sub
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
'I'm missing something in here, I just know it.
PrintInvoiceDialog.ShowDialog()
PrintInvoice.Print()
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
Me.Close()
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.
-
May 12th, 2005, 02:58 PM
#2
Thread Starter
Lively Member
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
-
May 13th, 2005, 08:33 AM
#3
Thread Starter
Lively Member
Re: Printing From Form . . .
-
May 13th, 2005, 01:29 PM
#4
Thread Starter
Lively Member
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:
Imports System.IO
'InvoiceBrowser is the name I gave the AxWebBrowser control on this page.
'This code simply gets the html file and renders it like IE would, plug-ins and all.
'I *do* need to add a catch in here if it can't find the base html file.
Private Sub InvoiceBrowser_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InvoiceBrowser.Enter
InvoiceBrowser.Navigate("C:\blah\blah\blah\invoice.htm")
End Sub
'This is the print event itself.
'It just uses the Javascript plug-in that *everybody* has in IE,
'I would think.
Private Sub mnuPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPrint.Click
InvoiceBrowser.Document.parentWindow.execScript("window.print();", "JScript")
End Sub
Private Sub mnuClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClose.Click
Me.Close()
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|