Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • Last Modified:

Default Printer

Is there a way to get the printer selected in a commondialog without changing the default printer?
0
Pennywisdom
Asked:
Pennywisdom
1 Solution
 
AzraSoundCommented:
if you list all the printers this way:

Dim X As Printer
For Each X In Printers
   List1.AddItem X.DeviceName
Next

then set it to one of the items in the list:

Set Printer = Printers(List1.ListIndex)


this should set the current printer but not actually change the default printer




0
 
PennywisdomAuthor Commented:
I wanted to use the commondialog because its a standard and as some options already done like the status of the printer
0
 
VoodoomanCommented:
Hi!

Well the Printer in the common dialog is the default Printer.

Printer.DeviceName

returns the selected/current printer

If its empty there is no Printer setup.

This is useful with many reporting tools which use the Printer Device Context to display - Crystal Reports does this.

If you intend your users to display reports its worth checking if there is a default printer to avoid errors!

If you want driver information etc it is available thru the Windows API

Azra Sound is probably right and I like his idea!!

Good Luck

Voodooman!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
GivenRandyCommented:
I have code doing what you say, if you want a sniplet of it.  Anyhow, use the "Printer.hDC".  This is referenced in online help:

With a CommonDialog control, this property returns a device context for the printer selected in the Print dialog box when the cdlReturnDC flag is set or an information context when the cdlReturnIC flag is set.

Note   The value of the hDC property can change while a program is running, so don't store the value in a variable; instead, use the hDC property each time you need it.

The AutoRedraw property can cause the hDC property setting to change. If AutoRedraw is set to True for a form or PictureBox container, hDC acts as a handle to the device context of the persistent graphic (equivalent to the Image property). When AutoRedraw is False, hDC is the actual hDC value of the Form window or the PictureBox container. The hDC property setting may change while the program is running regardless of the AutoRedraw setting.

If the HasDC property is set to False, a new device context will be created by the system and the value of the hDC property will change each time it is called.

0
 
GivenRandyCommented:
Also note that it does not change your default printer (that was our requirement also).
0
 
GivenRandyCommented:
Here is portions of the code (parts modified for proprietary reasons), which may help.  This uses a Common Dialog (frmDataFilter.cdMain) and RichTextBox (rtbResults):

On Error Resume Next

With frmDataFilter.cdMain
    .CancelError = True
    .Flags = cdlPDReturnDC + cdlPDHidePrintToFile + cdlPDNoPageNums + cdlPDNoSelection + cdlPDNoWarning
    .ShowPrinter
End With

If (Err.Number <> cdlCancel) Then
    rtbResults.Text = "Some data"
    rtbResults.SelPrint (Printer.hDC
End If

On Error Goto 0
0
 
RuchiCommented:
TAke a quick look at
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=4003

"“if you dont want the commondialog1.showprinter method to change your default printer. It also gets you out of using comdlg32.ocx. “
0
 
PennywisdomAuthor Commented:
This is exactly what I was looking for Thanks Alot!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now