Print File by using printing tools

PatelNehal4u

Active member
Joined
Apr 6, 2009
Messages
25
Programming Experience
1-3
Hello Friends,
I am new to this, so i installed visual studio 2008, i am learning use of dialog boxes. I created a form which maintain a .rtf file, now i want to print that file on printer using visual studio's various tools like, printdocument, printdialog and pagesetupdialog. Now i code the following for printdialog.

VB.NET:
Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click

        PrintDialog1.Document = PrintDocument1
        PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings
        PrintDialog1.AllowSomePages = True

        PrintDialog1.ShowHelp = True
        PrintDialog1.ShowNetwork = True


        If (PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
            'PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
            PrintDocument1.Print()
        End If
    End Sub

But now i am confused that how printdialog1 will know that which file it need to print. Please help me out....!!!
 

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
It's not printdialog1 that dictates what to print, it's PrintDocument1. You'll find two events related to PrintDocument1, BeginPrint and PrintPage. You would load the relevant RTF in BeginPrint (if it hasnt already been loaded) and then cycle through the PrintPage event until you have finished.

VB.NET:
Private Sub PrintDocument1_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
End Sub

As to how you actually print an RTF as WYSIWYG, that's a WHOLE different question. I dont think there is an easy way (although I may be wrong). If you wanted to print it as simple text, that would be easy.
 

PatelNehal4u

Active member
Joined
Apr 6, 2009
Messages
25
Programming Experience
1-3
I have a richtextbox tool which manage the current .rtf file. Now i want to print that file which is open in richtextbox1, so how can i inform the printdocument1 tool in BeginPrint event that you have to print file, which is open in richtextbox1 tool???
 

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
If the file is already loaded, you wouldnt need to - you'd just print the RichTextBox1.

As I said, it isnt easy - I think your solution is here
 
Last edited:
Top Bottom