Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Setting Print Dialog Flags

You can set a number of options in the Common Dialog control’s Flags property when working with the Print dialog box:

  cdlPDAllPages—&H0; returns or sets the state of the All Pages option button.
  cdlPDCollate—&H10; returns or sets the state of the Collate checkbox.
  cdlPDDisablePrintToFile—&H80000; disables the Print To File checkbox.
  cdlPDHelpButton—&H800; causes the dialog box to display the Help button.
  cdlPDHidePrintToFile—&H100000; hides the Print To File checkbox.
  cdlPDNoPageNums—&H8; disables the Pages option button and the associated edit control.
  cdlPDNoSelection—&H4; disables the Selection option button.
  cdlPDNoWarning—&H80; prevents a warning message from being displayed when there is no default printer.
  cdlPDPageNums—&H2; returns or sets the state of the Pages option button.
  cdlPDPrintSetup—&H40; causes the system to display the Print Setup dialog box rather than the Print dialog box.
  cdlPDPrintToFile—&H20; returns or sets the state of the Print To File checkbox.
  cdlPDReturnDC—&H100; returns a device context for the printer selection made in the dialog box. The device context is returned in the dialog box’s hDC property.
  cdlPDReturnDefault—&H400; returns the default printer name.
  cdlPDReturnIC—&H200; returns an information context for the printer selection made in the dialog box. An information context provides a fast way to get information about the device without creating a device context. The information context is returned in the dialog box’s hDC property.
  cdlPDSelection—&H1; returns or sets the state of the Selection option button. If neither cdlPDPageNums nor cdlPDSelection is specified, the All option button is in the selected state.
  cdlPDUseDevModeCopies—&H40000; if a printer driver doesn’t support multiple copies, setting this flag disables the Number Of Copies control in the Print dialog box. If a driver does support multiple copies, setting this flag indicates that the dialog box stores the requested number of copies in the Copies property.

You can set more than one flag for a dialog box using the Or operator. For example:

CommonDialog1.Flags = &H10& Or &H200&

Adding the desired constant values produces the same result.

Setting The Minimum And Maximum Pages To Print

When displaying a Print dialog box, you can set the minimum and maximum allowed values for the print range (in other words, the From and To pages to print) using the Min and Max properties of the Common Dialog control. The Min property sets the smallest number the user can specify in the From text box. The Max property sets the largest number the user can specify in the To text box. For example, here we restrict the possible pages to print to a maximum of 10, in the range 0 to 9:

Private Sub Command1_Click()
    Dim intLoopIndex As Integer

    On Error GoTo Cancel
    CommonDialog1.PrinterDefault = True
    CommonDialog1.Min = 0
    CommonDialog1.Max = 9
    CommonDialog1.ShowPrinter
    For intLoopIndex = 1 To CommonDialog1.Copies
        PrintForm
    Next intLoopIndex

Cancel:
End Sub

Now when the Print dialog box appears, you can see that in the Print Range box, at lower left in Figure 11.12, one option button says “All 10 Pages”. That is, we’ve set a maximum total of 10 pages for our document. The actual page range is from 0 to 9.


Figure 11.12  Setting print range in a Print dialog box.


TIP:  If the user enters a number outside the allowed From and To range and clicks on OK, an error message box will appear letting them know what the allowed range is.

Setting Page Orientation

When printing, you can set the page orientation—portrait (upright) or landscape (sideways)—with the Common Dialog control’s Orientation property. This setting is communicated to the printer automatically, but note that not all printers will be able to set a document’s orientation.

Here are the possible values for the Orientation property:

  cdlPortrait—1; documents are printed with the top at the narrow side of the paper (the default).
  cdlLandScape—2; documents are printed with the top at the wide side of the paper.

Here’s an example. In this case, we’re setting the printer’s Orientation property to landscape:

Private Sub Command1_Click()
    Dim intLoopIndex As Integer
    On Error GoTo Cancel
    CommonDialog1.PrinterDefault = True
    CommonDialog1.Orientation = cdlLandscape
    CommonDialog1.ShowPrinter
    For intLoopIndex = 1 To CommonDialog1.Copies
        PrintForm
    Next intLoopIndex

Cancel:
End Sub


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.