Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Desktop Developer

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

Search

XML Feeds

Google Ads

Tags: print

comments
Rate Post:
submit to reddit Digg!FacebookDotnetkicks

Today, I was looking for a method to Print the text that is in a RichTextbox. The printing of the text is no problem but keeping the formatting is a little more troublesome.

The first solutions you find use VB6 to accomplish this (by using an ActiveX control. But that was just not happening in my project.

Then, helped by an article on MSDN, I found the solution, which is actually just a com call and the same as what the others are doing. The code is in our wiki because I don’t want to bore you guys with all the details.

I used that to make an extension method for the richtextbox, which makes printing the contents of it a lot easier. Just do this

  1. RichTextBox1.Print()

or

  1. RichTextBox1.PrintPreview()

I also made it so that you can add a simple Header and Footer. Of course, you could make simple variations on them.

Here is an example of it at work in my home-made queryanalyser.

And then with this simple little code:

  1. CType(Me.TabControl1.SelectedTab.Controls(0), System.Windows.Forms.RichTextBox).PrintPreview(Me.TabControl1.SelectedTab.Text, "Printed On: " & Now.ToString("dd/MM/yyyy HH:mm"))

It gives this as a result:

Don’t forget, you can always ask questions about this in our VB.Net Forum

About the Author

User bio imageChristiaan is a forensic technician who programs on the side, although my function description says that I do IT-things for 90% of the time . I'm an avid VB.NET fan and I use lots of the ALT.Net techniques, like unit-testing, nhibernate, logging, IoC, ...
Social SitingsTwitterLinkedInHomePageLTD RSS Feed
2340 views
submit to reddit Digg!FacebookDotnetkicks

Comments and Feedback