I wrote this combo box component that will give the user a drop-down list of all available printers. When the user selects the printer, it becomes the current printer. i used it in a Crystal Reports viewer program:
unit PrintersCombo;
interface
uses
Windows, Messages, SysUtils, Classes, Printers,Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TPrintersCombo = class(TComboBox)
private
protected
procedure Click;override;
procedure CreateWnd; override;
public
CurrentPrinter:string;
constructor Create(AOwner: TComponent);override;
published
{ Published declarations }
property Style default csDropDown;
property Items stored False;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TPrintersCombo]);
end;
{ TPrintersCombo }
procedure TPrintersCombo.Click;
var
index:integer;
begin
inherited Click;
index:=0;
CurrentPrinter:=Text;
index:=Printer.Printers.IndexOf(CurrentPrinter);
Printer.PrinterIndex:=index;
end;
constructor TPrintersCombo.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Printer.PrinterIndex:=-1;
CurrentPrinter:=Printer.Printers[Printer.PrinterIndex];
Text:=CurrentPrinter;
Style:=csDropDown;
Width:=250;
Update;
end;
procedure TPrintersCombo.CreateWnd;
begin
inherited CreateWnd;
Items.Assign(Printer.Printers);
end;
end.