* * *

Author Topic: Show printer's properties box  (Read 5075 times)

Anypodetos

  • Newbie
  • Posts: 4
Show printer's properties box
« on: February 10, 2013, 10:27:11 am »
The PrintDialog brings up a window with a "properties" button, which in turn displays a printer specific window. Is there a way of skipping the PrintDialog window and showing tha printer specific one directly? (The first one contains a lot of things irrelevant to the programme I'm writing and thus potentially confusing for the user, such as the number of copies to print and whether to collate them.)
Cheers,
Anypodetos

howardpc

  • Hero Member
  • *****
  • Posts: 2806
Re: Show printer's properties box
« Reply #1 on: February 10, 2013, 01:10:09 pm »
You are probably looking for the TPrinterSetupDialog component. It is on the same Component Palette page as TPrintDialog (Dialogs).

Anypodetos

  • Newbie
  • Posts: 4
Re: Show printer's properties box
« Reply #2 on: February 10, 2013, 04:01:14 pm »
Only if I can get rid of the "Paper" and "Orientation" fields. But rather I'd have the functionality of the TPrinterSetupDialog "Properties" button accessible from my own form, say, something like a procedure PrinterPropertiesBox() that I can call from a button event handler.

howardpc

  • Hero Member
  • *****
  • Posts: 2806
Re: Show printer's properties box
« Reply #3 on: February 10, 2013, 10:41:48 pm »
The following unit shows how you can use the Printer object to obtain information via your own dialog. This example simply changes the current printer, but there is lots of information in the Printer class you can extract/change via a customised dialog. Here the function PrinterChangedTo returns the name of the new current printer, or an empty string if the current printer has not been changed. This (or a more capable adaptation) could easily be turned into a dialog component if preferred.

Code: [Select]
unit simple_print_dlg;

{$mode objfpc}{$H+}

interface

uses
  Forms, Controls, StdCtrls, ButtonPanel, Printers;

type

  TfrmPrintDlg = class(TForm)
    BPanel: TButtonPanel;
    CBPrinters: TComboBox;
    gbPrinter: TGroupBox;
    LName: TLabel;
  end;

function PrinterChangedToDlg: string;

implementation

function PrinterChangedToDlg: string;
var
  frm: TfrmPrintDlg;
begin
 Result:= '';
 if not Assigned(Printer) then Exit;
 if Printer.Printers.Count=0 then Exit;
 frm:= TfrmPrintDlg.Create(nil);
 try
   frm.CBPrinters.Items.Assign(Printer.Printers);
   frm.CBPrinters.ItemIndex:=0;
   if frm.ShowModal = mrOK then
     if (frm.CBPrinters.ItemIndex>0) then
      begin
       Printer.SetPrinter(Printer.Printers[frm.CBPrinters.ItemIndex]);
       Result:= Printer.Printers[frm.CBPrinters.ItemIndex];
      end;
 finally
   frm.Free;
 end;
end;

{$R *.lfm}

end.

The .lfm is as follows:
Code: [Select]
object frmPrintDlg: TfrmPrintDlg
  Left = 254
  Height = 173
  Top = 152
  Width = 320
  Caption = 'Printer Information'
  ClientHeight = 173
  ClientWidth = 320
  LCLVersion = '1.0.6.0'
  object gbPrinter: TGroupBox
    Left = 12
    Height = 113
    Top = 10
    Width = 300
    Caption = 'Printer'
    ClientHeight = 91
    ClientWidth = 296
    TabOrder = 0
    object LName: TLabel
      Left = 10
      Height = 21
      Top = 10
      Width = 91
      Caption = 'Printer Name:'
      ParentColor = False
    end
    object CBPrinters: TComboBox
      Left = 10
      Height = 28
      Top = 44
      Width = 276
      ItemHeight = 20
      ParentShowHint = False
      Style = csDropDownList
      TabOrder = 0
    end
  end
  object BPanel: TButtonPanel
    Left = 6
    Height = 38
    Top = 129
    Width = 308
    OKButton.Name = 'OKButton'
    OKButton.DefaultCaption = True
    HelpButton.Name = 'HelpButton'
    HelpButton.DefaultCaption = True
    CloseButton.Name = 'CloseButton'
    CloseButton.DefaultCaption = True
    CancelButton.Name = 'CancelButton'
    CancelButton.DefaultCaption = True
    TabOrder = 1
    ShowButtons = [pbOK, pbCancel]
  end
end

Anypodetos

  • Newbie
  • Posts: 4
Re: Show printer's properties box
« Reply #4 on: February 11, 2013, 03:16:50 pm »
Um, yes. I know the Printer class, and I already have a select printer combo box in my window, but still there doesn't seem to be a method to display the right box – see attachment – (printer driver specific) without displaying the left one (OS specific) first.

howardpc

  • Hero Member
  • *****
  • Posts: 2806
Re: Show printer's properties box
« Reply #5 on: February 11, 2013, 03:35:37 pm »
but still there doesn't seem to be a method to display the right box – see attachment – (printer driver specific) without displaying the left one (OS specific) first.
Because Lazarus is cross-platform it naturally uses the higher-level OS shell dialogs for functions as platform/driver/hardware-specific as printer settings.
All things are possible, of course, and in your case you could doubtless drop down to a Windows API call to show just the Properties dialog - and thereby lose any cross-platform capability.

jesusr

  • Sr. Member
  • ****
  • Posts: 455
Re: Show printer's properties box
« Reply #6 on: February 12, 2013, 08:41:47 pm »
All the available printer dialogs are demostated in lazarus/components/printers/samples/dialogs, have you checked that sample?

Anypodetos

  • Newbie
  • Posts: 4
Re: Show printer's properties box
« Reply #7 on: February 15, 2013, 08:51:03 pm »
Thanks for the sample! It contains exactly what I wanted to know:
Code: [Select]
  {$IFDEF MSWindows}
  TWinPrinter(Printer).AdvancedProperties;
  {$ELSE}
  ShowMessage('Printer.AdvancedProperties is not yet implemented for this platform');
  {$ENDIF}
  UpdatePrinterInfo;
which shows that this really isn't implemented on platforms other than Windows.

RayoGlauco

  • Jr. Member
  • **
  • Posts: 81
  • Beers: 1567
Re: Show printer's properties box
« Reply #8 on: June 10, 2018, 07:44:26 am »
If anyone is interested in it, I posted some code to access Windows printer settings here: http://forum.lazarus.freepascal.org/index.php/topic,41437.msg288290.html#msg288290
« Last Edit: June 12, 2018, 07:42:10 am by RayoGlauco »
To err is human, but to really mess things up, you need a computer.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus