vel21.htm

来自「简单的说明如何使用VB,非常适合初学使用者,而且是用图表来解说的」· HTM 代码 · 共 2,347 行 · 第 1/4 页

HTM
2,347
字号
9: Printer.EndDoc</FONT></PRE><P><FONT COLOR="#FF8000"><B><I>Analysis: </I></B></FONT>The program containing Listing 21.3's code might continue to run and process other sets of data. The EndDoc method triggered by line 9 ensures that the output built in the preceding Print methods all gets sent to the physical printer immediately. If other Print methods appear later in the program, the Print Manager will begin building the output all over again, releasing that subsequent output only for an EndDoc procedure or when the application ends.<BR><BR><A NAME="E68E163"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Page Breaks</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>When printing to the printer, you must be careful to print at the top of a new page when you want the output to advance one page. The NewPage method forces the printer to eject the current page and begin subsequent output on the next new page.<BR><P>The Windows Print Manager ensures that each printed page properly breaks at the end of a physical page. Therefore, if the printer's page length is 66 lines and you print 67 lines, the 67th line will appear at the top of the second page of output.<BR><P>There are times, however, when you need to print less than a full page on the printer. You can release that incomplete page for printing using the NewPage method (from Table 21.1). To use NewPage, simple apply the NewPage method to the Printer object like this:<BR><BR><PRE><FONT COLOR="#000080">printer.NewPage</FONT></PRE><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>Remember that you actually print to the Windows Print Manager and that your application's output methods don't directly control a physical printer. Therefore, NewPage tells the Print Manager to go the a new page when the Print Manager gets to that location in the output.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>You've got to remember that you're working with printers that support many fonts and font sizes. You can always determine, in advance, how many lines of output will fit on a single page as long as you first check the value of the following formula:<BR><BR><PRE><FONT COLOR="#000080">numLinesPerPage = Printer.Height / Printer.TextHeight(&quot;X&quot;)</FONT></PRE><P>As explained in Table 21.1, the Height property determines the height, in twips, of the page. The TextHeight property determines the full height of a printed character (including <I>leading</I>, which is the area directly above and below characters). TextHeight measures the height in twips if you haven't changed the scale using the ScaleMode property.<BR><P>For printed reports, you'll rarely use the ScaleMode method. If you have the need to change the scale of measurement, however, you'll have to change the scale back to twips before calculating the number of output lines per page, like this:<BR><BR><PRE><FONT COLOR="#000080">printer.ScaleMode = TWIPS</FONT></PRE><P>The ScaleMode accepts values defined in Table 21.3. As long as you add the CONSTANT.TXT file to your application's Property window, you can use the named constants in place of the numeric values if you want to change the scale measurement.<BR><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 21.3. The </B><B>ScaleMode</B><B> values.</B></FONT></CENTER><BR><TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 ><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Value</I></FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Named Constant</I></FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Description</I></FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>0</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>USER</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>A user-defined value</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>1</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>TWIPS</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Measured in twips (the default)</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>2</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>POINTS</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Measured in points</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>3</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>PIXELS</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Measured in pixels (the smallest unit addressable by your printer)</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>4</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>CHARACTERS</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Measured in characters (120 by 240 twips)</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>5</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>INCHES</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Measured in inches</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>6</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>MILLIMETERS</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Measured in millimeters</FONT><TR><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>7</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>CENTIMETERS</FONT><TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>Measured in centimeters</FONT></TABLE><P><FONT COLOR="#FF8000"><B><I>Stop and Type: </I></B></FONT>Listing 21.4 contains code that prints two messages, one per page of printed output.<BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>At any point during your application's printing, you can issue an NewPage method to force the printer to eject the current page and begin printing at the top of the next page.<BR><P><FONT COLOR="#000080"><B>Listing 21.4. The </B><B>NewPage</B><B> forces the printer to eject the current page.</B></FONT><BR><PRE><FONT COLOR="#000080">1: Printer.Print &quot;The Report begins on the next page...&quot;2: Printer.NewPage ' Go to top of new page3: Printer.Print &quot;The Campaign Platform&quot;</FONT></PRE><P><FONT COLOR="#FF8000"><B><I>Analysis: </I></B></FONT>Line 2 ejects the printer even if the printer has not yet printed a full page.<BR><BR><A NAME="E68E164"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Homework</B></FONT></CENTER></H3><BR><BR><A NAME="E69E150"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>General Knowledge</B></FONT></CENTER></H4><BR><OL><LI>What File command does the Visual Basic Primer system not support?<BR><BR><LI>What job does the Windows Print Manager play in printing your application's output?<BR><BR><LI>Why doesn't your program need to understand every printer's individual command?<BR><BR><LI>What does <I>online</I> mean?<BR><BR><LI>How can you ensure that the user prepares the printer before you print reports from a Visual Basic application?<BR><BR><LI>What is the Printer object?<BR><BR><LI>True or false: The Printer object supports properties and methods just as many of the controls do.<BR><BR><LI>What is a <I>pixel</I>?<BR><BR><LI>What is the most commonly used Printer method?<BR><BR><LI>True or false: You can print variables and constants but not expressions with Print.<BR><BR><LI>True or false: There is no difference between using several embedded Tab(14) functions and using commas to separate columns of output in a Print method.<BR><BR><LI>Printing three strings separated by commas causes the strings to appear in columns 1, 15, and 29. Why do you think that printing three positive numbers, separated by commas, causes the numbers to print in columns 2, 16, and 30?<BR><BR><LI>What is a <I>print zone</I>?<BR><BR><LI>True or false: A Print that isn't terminated with a trailing semicolon always prints a carriage return and line feed on the printer.<BR><BR><LI>How can you print quotation marks onto paper?<BR><BR><LI>True or false: If the last thing an application does before terminating is print a report, there is no need to specify the EndDoc method at the end of the printing.<BR><BR><LI>What is meant by <I>leading</I>?<BR><BR></OL><BR><A NAME="E69E151"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>Find the Bug</B></FONT></CENTER></H4><BR><OL><LI>Poor Caroline isn't having luck getting a report to print properly. Caroline learned in her early days of computing that a printed page has 66 lines of text. Now that Caroline has upgraded to Windows and is practicing to become a top-notch Visual Basic programmer, Caroline's 66-line per printed page doesn't seem to be true all of the time. Explain to Caroline what she must do to fix her problem.<BR><BR><LI>Mike is working on two programs. For some reason, Mike can't figure out why these two different output lines don't produce exactly the same output. Help Mike solve this dilemma.<BR>Printer.Print Tab(10); &quot;Visual Basic&quot;<BR>Printer.Print Spc(10); &quot;Visual Basic&quot;<BR><BR></OL><BR><A NAME="E69E152"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>What's the Output?</B></FONT></CENTER></H4><BR><OL><LI>What's the output from the following two Print methods?<BR>Printer.Print &quot;Line 1&quot;;<BR>Printer.Print &quot;Line 2&quot;<BR><BR><LI>What does the following Print method produce on the printer when the Print Manager releases the line to be printed?<BR>Printer.Print &quot;The Spanish N is &quot;; Chr$(164)<BR><BR></OL><BR><A NAME="E69E153"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>Write Code That...</B></FONT></CENTER></H4><BR><OL><LI>Write a line of Visual Basic code that prints the word America in column 57.<BR><BR></OL><BR><A NAME="E69E154"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>Extra Credit</B></FONT></CENTER></H4><BR><P>Write a program that prints the ASCII characters (print only the values from ASCII 32 to 255) on a piece of paper when the user presses a command button.<BR><P ALIGN=LEFT><A HREF="velp10.htm" TARGET="_self"><IMG SRC="purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A><A HREF="#I0" TARGET="_self"><IMG SRC="purtop.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Page Top"></A><A HREF="index.htm" TARGET="_self"><IMG SRC="purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A><A HREF="vel22.htm" TARGET="_self"><IMG SRC="purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A></BODY></HTML>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?