Domanda

I have this code:

Private printDocument1 As New PrintDocument()
Private stringToPrint As String

Private Sub ReadFile()
    Dim docName As String = "print_doc.rtf"
    Dim docPath As String = fsPathPrintDoc
    printDocument1.DocumentName = docName
    Dim stream As New FileStream(docPath + docName, FileMode.Open)
    Try
        Dim reader As New StreamReader(stream)
        Try
            stringToPrint = reader.ReadToEnd()
        Finally
            reader.Dispose()
        End Try
    Finally
        stream.Dispose()
    End Try
End Sub

and I do the printing using:

ReadFile()
printDocument1.Print()

I want to print a rtf file using a VB.NET printdialog.show(), because in want to choose specific printers for printing, but my above code i dont have any idea, how i can embed printdialog here.

This is required because i want to print that file using printers available on different systems using network. Now all these available printers are available for me in print dialog, what i want is to simply print a particular file in my drive using printdialog()

Also, I tried to find a possibility to print a file using printdialog and printdocument but unfortunately failed.

Edit:

I found http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx but it does not includes printdialog

È stato utile?

Soluzione

You assign your PrintDocument to the PrintDialogs Document Property, it will then add the selected printer to your Document. You then print the Document as normal.

PrintDialog1.AllowSomePages = True 
PrintDialog1.ShowHelp = True 
PrintDialog1.Document = printDocument1 'Assign your Document here

Dim result As DialogResult = PrintDialog1.ShowDialog()

If (result = DialogResult.OK) Then
    printDocument1.Print()
End If 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top