Home
Username:
Password:
Microsoft Visual Basic 2005 Tutorials

Printing / Coding the PrintPreview




Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.


Learn More

Subtitles of the Movie

Another great feature of Visual Basic .NET is the print preview control. The print preview control allows you to view the printer's output on the screen and then choose whether to proceed with the printing or not, much like the standard print preview that you have in Word or Excel or any other Microsoft-type documents. To include the print preview control, you return to the Toolbox under the Printing Group and select the Print Preview Dialog Control. That places the print preview dialog one control in the components tray. Once again, you will need a point of interaction for the user, so I'll add another button on the form to allow the user to experiment with the print preview, changing to the text to print preview to identify its purpose. Now, to make the print preview functional, I need to write two lines of code with a print preview button. So I'll open up the code window for that button, which for the time being is simply called Button Two and we now need to write two lines of code in the event procedure for this button where the user selects the print preview option. The print preview dialog component uses the same print document component that you declared for the printer output. You assign the print document to the document property of the print preview dialog and execute the show dialog method. The same print page event procedure will execute as for the print document. The print preview dialog component is the key to the print preview. Once the control has been added to your forms component tray, you can then use it with the other objects in your program. The two lines of code necessary would be something like this. Now, I actually don't have a print document one print in this sample program, but the two lines of code are the same nevertheless in that you are specifying the print preview dialog one, which is the name of the object that's in the components tray and then the key statement is the show dialog method of the print preview dialog. Even though we don't actually have something to print in this example, I can still run the program and click on the print preview and we will still be able to see the functionality. So while the project is running, I click Print Preview and here is the Print Preview Dialog Box that shows. As you can see, you have some built-in options of choosing the appropriate zoom level, of clicking the Close Button, specifying pages and there is a print icon which, if pressed, would actually send the document to the printer. Of course, again, in this example there isn't a document to actually be viewed but recognize this is all that's necessary to set up a print preview. That is, to add the print preview dialog control onto the form and then add the two lines of code that we've discussed; print preview dialog and then the code.

Tutorial Information

Course: Microsoft Visual Basic 2005
Author: Arthur Lee
SKU: 33940
ISBN: 1-935320-10-6
Release Date: 2008-11-19
Duration: 7.5 hrs / 97 lessons
Work Files: Yes
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available