whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

50 Visitors Online


 
...place custom controls on a TPrintDialog?
Autor: Tillman Dickson
Homepage: http://www.dvdata.com
[ Print tip ]  

Tip Rating (2019):  
     


// 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;



 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners