Problem with the Print Dialog

Hello!

I'm using the Print Dialog Class in my VB.Net code and having problems selecting the correct network printer. I'm able to set up and change all printer parameter from my code and to start the print out using a printer settigs class.

Although the printer dialog keeps telling me that the document is being sent to the priter I have selected, it actually sents it to the printer selected as standard printer in Windows. Does anyone know what I'm doing wrong, or is there maybe a registry key I'm not aware of?

Here the code I wrote to use the printer dialog:

With pdgPrint
'basic settings for print dialog
'-
.AllowPrintToFile =True
.AllowSomePages =True
'create and populate the printer settings objects
'--
.PrinterSettings =New PrinterSettings
With .PrinterSettings
.PrintRange = PrintRange.SomePages
.FromPage = 1
.ToPage = maxPAGE
.MinimumPage = 1
.MaximumPage = maxPAGE
EndWith

'show the print dialog
'--
If .ShowDialog <> DialogResult.OKThen
.Dispose()
ExitSub
EndIf

If .PrinterSettings.PrintRange = PrintRange.SomePagesThen
'print the selected range of pages
'--
prnPages(.PrinterSettings.FromPage, .PrinterSettings.ToPage)
ElseIf .PrinterSettings.PrintRange = PrintRange.AllPagesThen
'print all pages of the specified LOC
'--
Dim lastPageAsInteger
If (pgNR = 255)Then lastPage = 1Else lastPage = pgCNT
prnPages(1, lastPage)
EndIf

EndWith

Thanks, Horst

[3405 byte] By [HorstW] at [2007-12-31]
# 1

Horstw,

It seems that the standard printer in Windows is not the printer you want to use. I recommend you to set the current printer as default or correctly in order too make sure the document in printed by the current printer. You can do it by code like this:

Public Sub Printing(ByVal printer As String)

Try

streamToPrint = New StreamReader(filePath)

Try

printFont = New Font("Arial", 10)

Dim pd As New PrintDocument()

AddHandler pd.PrintPage, AddressOf pd_PrintPage

' Specify the printer to use.

pd.PrinterSettings.PrinterName = printer

If pd.PrinterSettings.IsValid Then

pd.Print()

Else

MessageBox.Show("Printer is invalid.")

End If

Finally

streamToPrint.Close()

End Try

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Sub

BrunoYu-MSFT at 2007-9-7 > top of Msdn Tech,Visual Basic,Visual Basic Language...