Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 17 Working with Printers 421



  1. 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.


  1. 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.

  2. Use the Button control to draw a button object below the text box.


This button object will print the text file.


  1. 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.


  1. Double-click the Print Text button.


The Button1_Click event procedure appears in the Code Editor.


  1. 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.

Free download pdf