Rated
Read 103,603 times
Contents
Related Categories
Common Dialog Control - Using the Print Dialog
Using the Print Dialog
You can use the print dialog to allow the user to select printer settings,
which your application can then use to print. Below are the most common parameters
you will need to set before displaying the Print Dialog Box.
|
Parameter
|
Changes...
|
| DialogTitle |
the Title displayed in the Dialog Box |
| Printer Default |
whether to use the default printer |
| Flags |
custom settings such as print selection only |
| CancelError |
whether an error occurs when the dialog box is cancelled. |
The following code displays a print dialog, with page numbers disabled, and
then prints the text in RichTextBox1. It also returns the selected printer
CommonDialog1.PrinterDefault = True
CommonDialog1.CancelError = True
' Set flags - no page numbers, return the selected printer
CommonDialog1.Flags = cdlPDReturnDC + cdlPDNoPageNums
If RichTextBox1.SelLength = 0 Then
CommonDialog1.Flags = CommonDialog1.Flags + cdlPDAllPages
Else
CommonDialog1.Flags = CommonDialog1.Flags + cdlPDSelection
End If
' Enables error handling to catch cancel error
On Error Resume Next
' display the print dialog box
CommonDialog1.ShowPrinter
If Err Then
' This code runs if the dialog was cancelled
Msgbox "Dialog Cancelled"
Exit Sub
End If
' Prints the contents of RichTextBox
RichTextBox1.SelPrint (Printer.hDC)
James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.
Comments
-
Posted by ffrreeaakk on 20 Feb 2007
I know what you're thinking about. I have exactly the same problem. I don't know how to make Common Dialog Box show such window: http://Common Dialog Control
Posted by al_sebie on 26 Jul 2006
Dear Sir
Thanks for you help and I like you way that you got it, but my questation is Can I use Common Dialog without use File Type? because I need only open folder without select file "Onl...
Posted by takedownca on 20 Apr 2004
Using the FileName (path) and FileTitle (filename) properties of the dialog control,
[code]
Dim FilePathOnly As String
FilePathOnly = Left(FileName, Len(FileName) - Len(FileTitle))
'or
FilePath...
Posted by darkwolf on 24 Dec 2003
[code]OpenPath = App.Path & "\templates\"
OpenFileWName = TreeView1.SelectedItem
If OpenFileWName = OpenPath Then
MsgBox "You can not select a directory. Please select a template file."
E... -
Posted by darkwolf on 20 Dec 2003
is there a way of getting just the path of the file this way, without the file name in it?
E.G. if i open
C:\Windows\Wini.ini
can i get the program to read just
C:\Windows
from that?
|