For a print preview window, we need to be able to build the print output one page at a time. This means that for any given value of Page, we need to be able to create the printer document for that particular page. This can be more difficult than it looks.
Consider a word processor. To print any random page from the document means that you must clearly know where each page starts. For example, if someone inserted a line at the beginning of a 100-page document, you must go through and repaginate the entire document before you can print it. (Well this isn’t strictly true, all you really need to repaginate is the pages prior to the page you want to print, but you get the point.) This can be a very time-consuming process. Spreadsheets are a little easier when all of their rows are fixed in height, but you can’t always assume that is the case. Database reports can be tougher still, since they can get very large and complicated. How do you handle this? Generating output is a relatively straightforward task in BASIC. You simply use the Print statement.
The trick to building a print preview window with Visual Basic is to recognize that you should have only a method to generate the output for a specific page and then apply that method for each page as needed to complete the output. When sending the output to the printer, you simply generate all of the desired pages. When sending the output to the preview window, you generate one page and wait until the user requests the next page.