Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Expand Your VB6 Printing Repertoire—Part II-4 : Page 4


advertisement
Suggestions for Further Improvements
After displaying the page preview, the sample application uses a MessageBox to ask users whether it should display the following page. That's a primitive (and irritating) mechanism for previewing multiple pages, but I used it to avoid adding UI complexity to the sample application. You can—and should—design a much more functional interface for the preview form by adding a toolbar with Previous and Next buttons, allowing users to control how the application displays preview pages. You could also add page-selection capabilities, letting users begin previewing or printing any page in the document. Here's a hint: You can simplify the implementation of the interface by storing the location (the offset index) for the first character of each preview page in an array or collection and use that information to generate the preview of any page in the printout. Once you know the index of the first character on each page, you can quickly and easily jump to the preview of any particular page. You could also provide users with the option to specify a range of pages to print. To expose the Print Range section of the Print dialog box set the Min and Max properties of the CommonDialog control.

For more formal documents, you will probably want to add statements that print a header and footer, just outside the top and bottom margins. These elements could include a document title, the date, a page number, or any other information you see fit. Just select a different font size and style for the two elements and experiment with their location. This late in the programming game, you'd think it should be trivial to print straight text, but it isn't—it still takes quite a bit of code to print clearly. I think the TextBox control should support two methods for previewing and printing text, but that isn't even the case in Visual Studio .NET (the IDE for the newest version of Visual Basic). The code presented here is quite efficient—it takes less than a second to process a page. The basic limitation of the sample application is that you can't use the VB6's TextBox control to display strings that exceed 32K characters. You can replace the TextBox control with a RichTextBox control, which can hold a much larger amount of text, but if you do that you must also disable the control's formatting features, because the PrintText subroutine can't print formatted text (you can use the Print method of the RichTextBox control to print formatted text, but even the RichTextBox control can't preview document printouts). Next month, in the last part of this article series, you'll build a utility for printing tabular data, such as the items of the ListView control. This is the most complicated printing utility in the series, and will show you hot to mix fonts and styles in your printout.



Evangelos Petroutsos is a long time VB developer. When he's not writing code, he writes programming books and articles. His most recent title is Mastering Visual Basic .NET, published by Sybex. Reach him by e-mail here.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date