Lazarus
Programming => LCL => Topic started by: Anypodetos 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
-
You are probably looking for the TPrinterSetupDialog component. It is on the same Component Palette page as TPrintDialog (Dialogs).
-
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.
-
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.
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:
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
-
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.
-
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.
-
All the available printer dialogs are demostated in lazarus/components/printers/samples/dialogs, have you checked that sample?
-
Thanks for the sample! It contains exactly what I wanted to know:
{$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.
-
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 (http://forum.lazarus.freepascal.org/index.php/topic,41437.msg288290.html#msg288290)