Mega Code Archive

 
Categories / Delphi / Printing
 

How to place custom controls on a TPrintDialog

Title: How to place custom controls on a TPrintDialog // Unit for TExtendedPrintDialog unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtDlgs, extctrls, stdctrls, CommDlg, Dlgs; type TExtendedPrintDialog = class(TPrintDialog) private fExtendedPanel: TPanel; fCheckBoxOne, fCheckBoxTwo: TCheckbox; fButton: TButton; protected procedure DoShow; override; function GetStaticRect: TRect; function TaskModalDialog(DialogFunc: Pointer; var DialogData): Bool; override; public constructor Create(AOwner: TComponent); override; function Execute: Boolean; override; end; implementation constructor TExtendedPrintDialog.Create(AOwner: TComponent); var iTop: Integer; begin inherited; fExtendedPanel := TPanel.Create(Self); with fExtendedPanel do begin Name := 'ExtendedPanel'; Caption := ''; SetBounds(0, 0, 169, 200); // (204, 5, 169, 200); BevelOuter := bvNone; BorderWidth := 6; TabOrder := 1; fButton := TButton.Create(Self); with fButton do begin Name := 'SomeButton'; Caption := '&Options'; SetBounds(0, 10, 50, 21); Parent := fExtendedPanel; end; fCheckBoxOne := TCheckbox.Create(Self); with fCheckBoxOne do begin Name := 'CheckboxOne'; Caption := 'Upside-down print'; SetBounds(fButton.Left + fButton.Width + 10, 3, 110, 21); fCheckBoxOne.Parent := fExtendedPanel; end; fCheckBoxTwo := TCheckbox.Create(Self); with fCheckBoxTwo do begin Name := 'CheckboxTwo'; Caption := 'Sideways print'; SetBounds(fButton.Left + fButton.Width + 10, 23, 100, 21); Parent := fExtendedPanel; end; end end; procedure TExtendedPrintDialog.DoShow; var PreviewRect, StaticRect: TRect; begin { Set preview area to entire dialog } GetClientRect(Handle, PreviewRect); StaticRect := GetStaticRect; { Move extended area to right of static area } PreviewRect.Left := StaticRect.Left; PreviewRect.Top := StaticRect.Bottom; Inc(PreviewRect.Top, 4); fExtendedPanel.BoundsRect := PreviewRect; fExtendedPanel.ParentWindow := Handle; inherited DoShow; end; function TExtendedPrintDialog.Execute: Boolean; begin Template := 'DLGTEMPLATE';// this is in the extdlgs.rc Result := inherited Execute; end; function TExtendedPrintDialog.GetStaticRect: TRect; begin if Handle 0 then begin GetWindowRect(GetDlgItem(Handle, grp1), Result); // print range group box MapWindowPoints(0, Handle, Result, 2); end else Result := Rect(0, 0, 0, 0) end; function TExtendedPrintDialog.TaskModalDialog(DialogFunc: Pointer; var DialogData): Bool; begin TPrintDlg(DialogData).Flags := TPrintDlg(DialogData).Flags or PD_ENABLESETUPTEMPLATE; TPrintDlg(DialogData).lpSetupTemplateName := Template; Result := inherited TaskModalDialog(DialogFunc, DialogData); end; end. //Example, Beispiel: uses Unit2; procedure TForm1.Button1Click(Sender: TObject); var PrintDialog: TExtendedPrintDialog; begin PrintDialog := TExtendedPrintDialog.Create(nil); if PrintDialog.Execute then {do soemthing} end;