June 2003
Intermediate to advanced
800 pages
34h 20m
English
You want to center text vertically or horizontally on a page.
Calculate the available space between the margins, subtract the width or height of the text you want to print (using the Graphics.MeasureString and Font.GetHeight methods), and divide by two to find the appropriate coordinate.
Printing centered text is easy. The only caveat is that you need to perform the coordinate calculations, as with all print operations.
Here is a code snippet that prints a block of three lines of text that are centered horizontally and vertically:
Private Sub MyDoc_PrintPage(ByVal sender As Object, _ ByVal e As PrintPageEventArgs) ' Define the font and text. Dim Font As New Font("Arial", 35) Dim Text As String = "This is ...Read now
Unlock full access