Link to home
Start Free TrialLog in
Avatar of KOCUBA
KOCUBA

asked on

RichTextBox Printing

I have had an already written application thrown at me and don't have time to work on it and was wondering if someone would know a quick fix for this.  I have a rich text box on a form
that it populate with a rtf file that was chosen on a previous screen.  When the print button it click the contents of the box are printed out, but not how the rtf file was created (ie page breaks and font size).  I was wondering what would be the best way to print this out the way that a rtf file would look if it were brought up in say MS Word
Avatar of psmith789
psmith789

object.SaveFile(pathname, 0)

{the 0 designates an RTF file save)

and then print it with Word

OR use the following to print selected text in the control, or the whole thing if no text is selected.

Private Sub cmdPrint_Click()
   ' The CommonDialog control is named "dlgPrint."
   
   dlgPrint.Flags = cdlPDReturnDC + cdlPDNoPageNums
   If rtfData.SelLength = 0 Then
      dlgPrint.Flags = dlgPrint.Flags + cdlPDAllPages
   Else
      dlgPrint.Flags = dlgPrint.Flags + cdlPDSelection
   End If
   dlgPrint.ShowPrinter
   rtfData.SelPrint dlgPrint.hDC
End Sub

Check out this microsot KB Article...

HOWTO: Set Up the RichTextBox Control for WYSIWYG Printing
http://support.microsoft.com/support/kb/articles/Q146/0/22.asp 
 
Cheers!
Avatar of KOCUBA

ASKER

psmith789,

I found this answer in the MSDN Library and tried it. It does not work they way I want. I want to it print out the page breaks also, not just to the end of the page when I bring the file up in word it prints out correctly.

mcrider,

I am looking into your answer, but it will take more time than I wanted to spend on it, so it is going to take me awhile
Avatar of KOCUBA

ASKER

mcrider,

This basically does the same thing as the previous answer.  It does not include the page breaks the way that they are when I look at the document in word.  It just prints a full page and then goes on to the next one,ignore the page break.  The only thing that I can think of do to now is to have the application bring up word and have the user print it out in that.

Any thoughts

Dave
I think that may be your best bet - it is klunky, but then you get the entire Word engine to do the rendering and the printing.

Other option would be to look for a component to do it - especially if the formatting is not very complex.
Avatar of KOCUBA

ASKER

I have found my answer in a previuosly asked question.
I think the Question ID is 10131935
KOCUBA,

Glad you found your answer! Go to the Experts Exchange forum and ask them to close this thread and refund your 75 points. Be sure to mention this question number: Q.10232726


Cheers!
ASKER CERTIFIED SOLUTION
Avatar of ianB
ianB

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial