Forum > LCL

Show printer's properties box

(1/2) > >>

Anypodetos:
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:
You are probably looking for the TPrinterSetupDialog component. It is on the same Component Palette page as TPrintDialog (Dialogs).

Anypodetos:
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:
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: ---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.

--- End code ---

The .lfm is as follows:

--- Code: ---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

--- End code ---

Anypodetos:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version