Chapter 17 Working with Printers 421
- Use the TextBox control to draw a text box object below the label object.
The text box object will contain the text you want to print.
- Set the Multiline property of the text box object to True, and then expand the text box
so that it’s large enough to enter several lines of text. - Use the Button control to draw a button object below the text box.
This button object will print the text file.
- Set the following properties for the objects on your form:
Object Property Setting
Label1 Text “Type some text in this text box object, then click Print Text .”
TextBox1 ScrollBars Vertical
Button1 Text “Print Text”
Form1 Text “Print Text”
Your form looks similar to this:
Now add the program code necessary to print the contents of the text box.
- Double-click the Print Text button.
The Button1_Click event procedure appears in the Code Editor.
- Scroll to the very top of the form’s code, and then type the following Imports
declaration:
Imports System.Drawing.Printing
This makes it easier to reference the classes in the System.Drawing.Printing namespace,
which includes the PrintDocument class.