We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9
Using the PrintDocument
Control CHAPTER 6: PRINT METHOD Using the Print method to print reports from your application. THE PRINTDOCUMENT CONTROL
¡ This control allows you to send output to the printer.
¡ To place a PrintDocument control on a form:
Double-click the PrintDocument tool in the Printing
1 section of the Toolbox
Appears in the component tray at design time
2 because the control is invisible at runtime.
Use the prefix pd when naming the control
3 THE PRINT METHOD
¡ The PrintDocument control has a Print method that
starts the printing process using the following general format: PrintDocumentControl.Print()
¡ When the method is called, it triggers a PrintPage
event. ¡ You must write code in the event handler to initiate printing. THE PRINTPAGE EVENT (1 OF 2)
¡ To create a PrintPage event handler code template:
¡ Double-click the PrintDocument control in the component tray ¡ The event handler code template appears in the Code window:
Private Sub pdPrint_PrintPage(...) Handles pdPrint.PrintPage
End Sub THE PRINTPAGE EVENT (2 OF 2)
¡ Inside the PrintPage event handler
¡ You write code that sends text to the printer using a specified: ¡ Font ¡ Color ¡ Location ¡ With the e.Graphics.DrawString method THE E.GRAPHICS.DRAWSTRING METHOD (1 OF 3)
¡ The general format to call e.Graphics.DrawString
method:
e.Graphics.DrawString(String, New Font(FontName,
Size, Style), Brushes.Black, HPos, VPos) The name of the font The size of the The string to be printed to use font in points
e.Graphics.DrawString(String, New Font(FontName,
Size, Style), Brushes.Black, HPos, VPos) The vertical position of the The font style (bold, output italic, regular, strikeout The horizontal or underline) The output should position of the be printed in black output
THE E.GRAPHICS.DRAWSTRING METHOD
(2 OF 3) THE E.GRAPHICS.DRAWSTRING METHOD (3 OF 3)
¡ The following PrintPage event handler prints the string
“Sales Report” in abold 18 point Courier font. The horizontal and vertical coordinates of the output are 150 and 80.
Private Sub pdPrint_PrintPage(…) Handles pdPrint.PrintPage
e.Graphics.DrawString(“Sales Report”, New Font(“Courier”, 18, FontStyle.Bold), Brushes.Black, 150, 80) End Sub END OF CHAPTER 6