engloon

Hi.
I have a new window application that allow user to print according to their needs.

Friend WithEvents prnPrintbot As System.Windows.Forms.

With prnPrintbot
.AllowCurrentPage = True
.AllowSomePages = True
End With
If prnPrintbot.ShowDialog(Me) = DialogResult.OK Then
Dim intStartPage As Integer, intEndPage As Integer, i As Integer

Select Case prnPrintbot.PrinterSettings.PrintRange

End Select
For i = intStartPage To intEndPage
webBackgroundPrint.Navigate(url)
webBackgroundPrint.Print()
Next
End If


Unfortunately, when the print dialog box showed, it doesn't repond to the first mouse click. Meaning it would only respond on the second click for all available button in the dialog box.
Please help.


Re: Windows Forms General System.Windows.Forms.PrintDialog doesn't respond to first time click.

Yu Guo – MSFT

Hi, engloon,

It seems you are using a hidden WebBrowser to print, aren't you

If so, I don't think you can use a PrintDialog to change the printer settings for your WebBrowser.

Because a PrintDialog is used to set the printer settings for a PrintDocument

http://msdn2.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx

http://msdn2.microsoft.com/en-us/library/system.windows.forms.printdialog.aspx

And for a WebBrowser, we usually print it in its DocumentCompleted event.

For example

Private webbrowser As WebBrowser

Code Block

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

webbrowser = New WebBrowser()

AddHandler webbrowser.DocumentCompleted, AddressOf webbrowser_DocumentCompleted

webbrowser.Navigate("http://www.microsoft.com")

End Sub

Private Sub webbrowser_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)

webbrowser.Print()

End Sub

Hope this helps,

Regards






Re: Windows Forms General System.Windows.Forms.PrintDialog doesn't respond to first time click.

engloon

Hi Yuo Guo.

I just went through the code you provided, and it works.I have few genereted html pages to be printed, I tried to modify your code but I failed.

Please give me some clues on how to print multiple pages using the DocumentCompleted event.

And thanks for your help in advance.





Re: Windows Forms General System.Windows.Forms.PrintDialog doesn't respond to first time click.

Yu Guo – MSFT

Hi, engloon,

I think you cannot print the pages because you just navigate to another page even if the current page is not navigated.

So, I think a easy way is to create a bunch WebBrowser instance to print.
For example

Code Block

Private browsers As WebBrowser()

Private urls As String()

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

urls = New String(1) {}

urls(0) = "http://www.google.com"

urls(1) = "http://www.microsoft.com"

browsers = New WebBrowser(urls.Length - 1) {}

For i As Integer = 0 To browsers.Length - 1

browsers(i) = New WebBrowser()

AddHandler browsers(i).DocumentCompleted, AddressOf browser_DocumentCompleted

Next

End Sub

Private Sub browser_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)

TryCast(sender, WebBrowser).Print()

End Sub

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

For i As Integer = 0 To browsers.Length - 1

browsers(i).Navigate(urls(i))

Next

End Sub

Hope this helps,
Regards