-
November 1st, 2003, 10:21 PM
#1
Printing Dialog Box
What's up?
I'm trying to find a way for VB to open up a printer dialogbox within the application, so I can choose which printer I want to use to print up the entire VB form that I'm currently viewing. Any suggestions? THanks!
Chris
-
November 2nd, 2003, 12:07 AM
#2
Below is how to invoke the Print common dialog, in which I assume you can freely select a printer.
Code:
Private Sub Command1_Click()
With Cdlg
.Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly
.ShowOpen
End With
End Sub
Flags possible values have different meaning and effect
depending on which dialog are you showing
(ie: OpenFile, Print, Font,...)
Have a nice day,
Cesare Imperiali
'---------------------------------------------------------------------------
From msdn: flag possible values
CommonDialog Control Constants
File Open/Save Dialog Box Flags
Constant Value Description
cdlOFNAllowMultiselect = &H200
Specifies that the File Namelist box allows multiple selections.
The user can select more than one file atrun time by pressing the
SHIFT key and using the UP ARROW and DOWN ARROW keys to
select the desired files. When this is done, the FileName property
returns a string containing the names of all selected files. The
names in the string are delimited by spaces.
cdlOFNCreatePrompt = &H2000
Specifies that the dialog box prompts the user to create a file
that doesn't currently exist. This flag automatically sets the
cdlOFNPathMustExist and cdlOFNFileMustExist flags.
cdlOFNExplorer =&H80000
Use the Explorer-like Open A File dialog box template. Common
dialogs that use this flag do not work under Windows NT using
the Windows 95 shell.
CdlOFNExtensionDifferent = &H400
Indicates that the extension of the returned filename is different
from the extension specified by the DefaultExt property. This flag
isn't set if the DefaultExt property is Null, if the extensions match,
or if the file has no extension. This flag value can be checked
upon closing the dialog box.
cdlOFNFileMustExist = &H1000
Specifies that the user can enter only names of existing files in
the File Name text box. If this flag is set and the user enters an
invalid filename, a warning is displayed. This flag automatically
sets the cdlOFNPathMustExist flag.
cdlOFNHelpButton =&H10
Causes the dialog box to display the Help button.
cdlOFNHideReadOnly = &H4
Hides the Read Onlycheck box.
cdlOFNLongNames =&H200000
Use long filenames.
cdlOFNNoChangeDir= &H8
Forces the dialog box to set the current directory to what it was
when the dialog box was opened.
CdlOFNNoDereferenceLinks = &H100000
Do not dereference shell links (also known as shortcuts). By
default, choosing a shell link causes it to be dereferenced by the
shell.
cdlOFNNoLongNames = &H40000
Do not use long file names.
CdlOFNNoReadOnlyReturn = &H8000
Specifies that the returned file won't have the Read Only
attribute set and won't be in a write-protected directory.
cdlOFNNoValidate = &H100
Specifies that the common dialog box allows invalid characters in
the returned filename.
cdlOFNOverwritePrompt= &H2
Causes the Save As dialog box to generate a message box if the
selected file already exists. The user must confirm whether to
overwrite the file.
cdlOFNPathMustExist = &H800
Specifies that the user can enter only validpaths. If this flag is set
and the user enters an invalid path, a warning message is
displayed.
cdlOFNReadOnly = &H1
Causes the Read Only check box to be initially checked when the
dialog box is created. This flag also indicates the state of the
Read Only check box when the dialog box is closed.
CdlOFNShareAware =&H4000
Specifies that sharing violation errors will be ignored.
Color Dialog Box Flags
Constant Value Description
cdlCCFullOpen= &H2
Entire dialog box is displayed, including the Define Custom Colors
section
cdlCCShowHelp = &H8
Causes the dialog box to display a Help button
cdlCCPreventFullOpen = &H4
Disables the Define Custom Colors command button and prevents
the user from defining custom colors
cdlCCRGBInit = &H1
Sets the initial color value for the dialog box
Fonts Dialog Box Flags
Constant Value Description
cdlCFANSIOnly =&H400
Specifies that the dialog box allows only a selection of the fonts
that use the Windows character set. If this flag is set, the user
won't be able to select a font that contains only symbols.
cdlCFApply = &H200
Enables the Apply button on the dialog box.
cdlCFBoth = &H3
Causes the dialog box to list the available printer and screen
fonts. The hDC property identifies thedevice context associated
with the printer.
cdlCFEffects = &H100
Specifies that the dialog box enables strikethrough, underline,
and color effects.
cdlCFFixedPitchOnly = &H4000
Specifies that the dialog box selects only fixed-pitch fonts.
cdlCFForceFontExist = &H10000
Specifies that an error message box is displayed if the user
attempts to select a font or style that doesn't exist.
cdlCFHelpButton = &H4
Causes the dialog box to display a Help button.
cdlCFLimitSize = &H2000
Specifies that the dialog box selects only font sizes within the
range specified by the Min and Max properties.
cdlCFNoFaceSel = &H80000
No font name selected.
cdlCFNoSimulations = &H1000
Specifies that the dialog box doesn't allow graphic device
interface (GDI) font simulations.
cdlCFNoSizeSel = &H200000
No font size selected.
cdlCFNoStyleSel = &H100000
No style was selected.
cdlCFNoVectorFonts = &H800
Specifies that the dialog box doesn't allow vector-font selections.
cdlCFPrinterFonts = &H2
Causes the dialog box to list only the fonts supported by the
printer, specified by the hDC property.
cdlCFScalableOnly = &H20000
Specifies that the dialog box allows only the selection of fonts
that can be scaled.
cdlCFScreenFonts = &H1
Causes the dialog box to list only the screen fonts supported by
the system.
cdlCFTTOnly = &H40000
Specifies that the dialog box allows only the selection of TrueType
fonts.
cdlCFWYSIWYG = &H8000
Specifies that the dialog box allows only the selection of fonts
that are available on both the printer and on screen. If this flag is
set, the cdlCFBoth and cdlCFScalableOnly flags should also be
set.
Printer Dialog Box Flags
Constant Value Description
cdlPDAllPages = &H0
Returns or sets the state of the All Pagesoption button.
cdlPDCollate =&H10
Returns or sets the state of the Collatecheck box.
cdlPDDisablePrintToFile = &H80000
Disables the Print To File check box.
cdlPDHelpButton = &H800
Causes the dialog box to display the Help button.
cdlPDHidePrintToFile =&H100000
Hides the Print To File check box.
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 check box.
cdlPDReturnDC = &H100
Returns adevice 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 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 copies edit control. 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.
Help Constants
Constant Value Description
cdlHelpCommandHelp = &H102
Displays Help for a particular command
cdlHelpContents =&H3
Displays the contents topic in the current Help file
cdlHelpContext =&H1
Displays Help for a particular topic
cdlHelpContextPopup = &H8
Displays a topic identified by a context number
cdlHelpForceFile = &H9
Creates a Help file that displays text in only one font
cdlHelpHelpOnHelp = &H4
Displays Help for using the Help application itself
cdlHelpIndex = &H3
Displays the index of the specified Help file
cdlHelpKey = &H101
Displays Help for a particular keyword
cdlHelpPartialKey = &H105
Calls the search engine in Windows Help
cdlHelpQuit = &H2
Notifies the Help application that the specified Help file is no
longer in use
cdlHelpSetContents = &H5
Designates a specific topic as the contents topic
cdlHelpSetIndex = &H5
Sets the current index for multi-index Help
The name of the required component in your project is "Microsoft Common Dialog Control".
-
November 3rd, 2003, 04:59 PM
#3
Cool
So where does the code after the dotted line
'---------------------------------------------------------------------------
go?
also what variable type should name Cdlg?
chris
-
November 6th, 2003, 03:21 PM
#4
Printer problem
If you look at my website you can download my program, if you print the labels you get the option to select the printer you require.
If this is the type of thing you are looking for let me know and I will email you the code.
www.dispatch-labels.com
Regards,
Mark.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|