Formatting a Print Page in C# Windows Form Application

Introduction

In this article I am describing about some printing tricks and tips. I have read many articles about C# printing but, I could not find the following points.

So this will be helpful to beginners.

  1. Printing string from right to left.
  2. Printing string from centre to both sides.
  3. Printing a Title with bold and underline.
  4. Printing an image as background.
  5. Text wrap in printing
  6. Printing a ListView.

Let us start…..

Printing a String From Right to Left.

Normally we print a word from left to right. There is no code for that. But if you want to print from right you can use following code.

 

In here I wrote a stringFormat as “format” and used in the e.Graphics.Drawstring method. By this the text entered in the label will print from right to left.

Printing a string from centre to both sides.

The Code


Printing a Title with Bold and Underline.

Sometimes you will want to print a document title with bold and underlined. You can use following code for that.



Printing an image as background.

Here is the code to print an image which is stored in Properties.Resorces. Firstly store saved image to the Image Variable. Then the code to print image as background.

 
Text wrap in Printing

If our text is too long , we have to expand this to next line, this is text wrap. I have replaced "RectangleF" against "Point". Code is given below. Please check. 
Printing a ListView.