Ir para conteúdo
Fórum Script Brasil
  • 0

QuickReport


dan_visualdm

Pergunta

pessoal, fiz aqui tudo certinho no QR e beleza, ele fltra os dados do BD e exibe para imprimir somente o que o usuario desejar... até ai belezinhaa!!

o problema é que no preview antes de imprimir aparece em zoom to width porém eu queria que ficasse sempre em 100%... como fazer isso?

obrigado!

Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 0
o problema é que no preview antes de imprimir aparece em zoom to width porém eu queria que ficasse sempre em 100%... como fazer isso?

Voce pode montar um preview personalizado usando o componente QuickRep ou pode puxar este exemplo:

arquivo DFM

http://www.bsdg.org/SWAG/DELPHI/0312.PREVIEW.ZIP

Descrição da Unit

Angus Johnson
ajohnson@rpi.net.au

unit Preview;  { dfm file is at end .. use XX34 to decode }

interface

uses
  SysUtils, Classes, Controls, Forms, Quickrep, ExtCtrls, Messages,
  StdCtrls, Buttons, WinTypes, WinProcs, Dialogs, Printers,
  IniFiles;

type
  TFmPreview = class(TForm)
     Panel1: TPanel;
     QRPreview1: TQRPreview;
     Label1: TLabel;
     PrintDialog1: TPrintDialog;
     bbPrev: TBitBtn;
     bbNext: TBitBtn;
     bbZoomOut: TBitBtn;
     bbZoomW: TBitBtn;
     bbZoomIn: TBitBtn;
     bbPrint: TBitBtn;
    bbClose: TBitBtn;
     procedure FormShow(Sender: TObject);
     procedure bbZoomOutClick(Sender: TObject);
     procedure bbZoomWClick(Sender: TObject);
     procedure bbPrevClick(Sender: TObject);
     procedure bbNextClick(Sender: TObject);
     procedure bbPrintClick(Sender: TObject);
     procedure bbZoomInClick(Sender: TObject);
     procedure bbCloseClick(Sender: TObject);
     procedure FormActivate(Sender: TObject);
     procedure FormClose(Sender: TObject; var Action: TCloseAction);
     procedure FormKeyDown(Sender: TObject; var Key: Word;
       Shift: TShiftState);
  private
     procedure CMDialogKey(var message: TCMDialogKey); message CM_DIALOGKEY;
  public
  end;

var
  FmPreview: TFmPreview;

implementation

uses
  Main;

{$R *.DFM}


procedure TFmPreview.FormShow(Sender: TObject);
begin
    QRPreview1.Zoom := 100; {defaults to ZoomIn}
    Label1.caption := 'Page 1 of ' +inttostr(QRPrinter.PageCount);
    if QRPrinter.PageCount = 1 then bbNext.enabled := false
    else bbNext.enabled := true;
    bbClose.setfocus;
    bbZoomIn.enabled := false;
    bbZoomW.enabled := true;
    bbZoomOut.enabled := true;
end;

procedure TFmPreview.bbZoomOutClick(Sender: TObject);
begin
    QRPreview1.ZoomToFit;
    bbZoomOut.enabled := false;
    bbZoomW.enabled := true;
    bbZoomIn.enabled := true;
    bbClose.setfocus;
end;

procedure TFmPreview.bbZoomWClick(Sender: TObject);
begin
    QRPreview1.ZoomToWidth;
    bbZoomW.enabled := false;
    bbZoomOut.enabled := true;
    bbZoomIn.enabled := true;
    bbClose.setfocus;
end;

procedure TFmPreview.bbPrevClick(Sender: TObject);
begin {Previous page}
  if QRPreview1.PageNumber > 1 then
         QRPreview1.PageNumber := QRPreview1.PageNumber-1;
  Label1.caption := 'Page ' + inttostr(QRPreview1.PageNumber)+
                        ' of ' +inttostr(QRPrinter.PageCount);
  bbNext.enabled := true;
  if QRPreview1.PageNumber = 1 then begin
     bbPrev.enabled := false;
     bbNext.setfocus;
  end;
end;

procedure TFmPreview.bbNextClick(Sender: TObject);
begin {Next page}
  if QRPreview1.PageNumber < QRPrinter.PageCount then
                    QRPreview1.PageNumber := QRPreview1.PageNumber+1;
  Label1.caption := 'Page ' + inttostr(QRPreview1.PageNumber)+
                    ' of ' +inttostr(QRPrinter.PageCount);
  bbPrev.enabled := true;
  if QRPreview1.PageNumber = QRPrinter.PageCount then begin
     bbNext.enabled := false;
     bbPrev.setfocus;
  end;
end;

procedure TFmPreview.bbPrintClick(Sender: TObject);
begin
  {A PrintDialog component can be added to the form with an -
  if not PrintDialog1.execute then exit -
  statement placed here.}
  screen.cursor := crHourglass;
  try
     QRPrinter.Print;
     while tag > 1 do begin
       QRPrinter.Print;
       tag := tag-1;
     end;
     tag := 1;
  finally
     screen.cursor := crDefault;
  end;
  close;
end;

procedure TFmPreview.bbZoomInClick(Sender: TObject);
begin
    QRPreview1.Zoom := 100;
    bbZoomIn.enabled := false;
    bbZoomW.enabled := true;
    bbZoomOut.enabled := true;
    bbClose.setfocus;
end;

procedure TFmPreview.bbCloseClick(Sender: TObject);
begin
    close;
end;

procedure TFmPreview.FormActivate(Sender: TObject);
var
  TrayHwnd: HWnd;
  Rect: TRect;
  CxFullScreen, CyFullScreen, CyCaption: integer;
begin
  {size the form to fill the screen...}
  TrayHwnd := FindWindow('Shell_TrayWnd','');
  if TrayHwnd = 0 then {not Win95 screen}
     WindowState := wsMaximized
  else begin
     GetWindowRect(TrayHwnd,Rect);
     CxFullScreen    := GetSystemMetrics(SM_CXFULLSCREEN);
     CyFullScreen    := GetSystemMetrics(SM_CYFULLSCREEN);
     CyCaption       := GetSystemMetrics(SM_CYCAPTION);

     {NOTE: Position must equal either poDefault or poDesigned,
      and WindowState = wsNormal}
     Top      := 0;
     Left     := 0;
     Width    := CxFullScreen;
     Height   := CyFullScreen + CyCaption;

     if (Rect.Top < 0) and (Rect.Left < 0) then begin
       {Taskbar on either top or left}
       if Rect.Right > Rect.Bottom then {Taskbar on top}
         Top  := Rect.Bottom
       else {Taskbar on left}
         Left := Rect.Right;
     end;
  end;
  bbClose.left := width - 76;
  bbPrint.left := width - 144;
end;

procedure TFmPreview.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  QRPreview1.PageNumber := 1; {this is necessary if reopening form!!!?}
  bbPrev.enabled := false;
  QRPreview1.HorzScrollbar.Position := 0;
  QRPreview1.VertScrollbar.Position := 0;
end;

procedure TFmPreview.CMDialogKey(var message: TCMDialogKey);
begin {INTERCEPTS ARROW KEYS INORDER TO MOVE AROUND PAGE}
  with message do
     case CharCode of
       VK_LEFT: begin
         with QRPreview1.HorzScrollbar do Position := Position -50;
         exit;
         end;
        VK_RIGHT: begin
         with QRPreview1.HorzScrollbar do Position := Position +50;
         exit;
         end;
        VK_UP: begin
         with QRPreview1.VertScrollbar do Position := Position -50;
         exit;
         end;
        VK_DOWN: begin
         with QRPreview1.VertScrollbar do Position := Position +50;
         exit;
         end;
     end;
  inherited;
end;

procedure TFmPreview.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin {INTERCEPTS [PG_UP],[PG_DN], [CTRL][PG_UP],[CTRL][PG_DN], [HOME],[END]}
  if (((Key = VK_NEXT) and (Shift = [ssCtrl])) or (Key = VK_END))
                                            and bbNext.enabled then begin
     QRPreview1.PageNumber := QRPrinter.PageCount; {GOTO LAST PAGE}
     Label1.caption := 'Page ' + inttostr(QRPrinter.PageCount)+
                      ' of ' +inttostr(QRPrinter.PageCount);
     bbPrev.enabled := true;
     bbNext.enabled := false;
     bbPrev.setfocus;
     end
  else if (((Key = VK_PRIOR) and (Shift = [ssCtrl])) or (Key = VK_HOME))
                                             and bbPrev.enabled then begin
     QRPreview1.PageNumber := 1; {GOTO FIRST PAGE}
     Label1.caption := 'Page 1' +
                      ' of ' +inttostr(QRPrinter.PageCount);
     bbPrev.enabled := false;
     bbNext.enabled := true;
     bbNext.setfocus;
     end
  else if (Key = VK_NEXT) and bbNext.enabled then bbNextClick(Sender)
  else if (Key = VK_PRIOR) and bbPrev.enabled then bbPrevClick(Sender);
end;

end.

abraço

Link para o comentário
Compartilhar em outros sites

  • 0
o problema é que no preview antes de imprimir aparece em zoom to width porém eu queria que ficasse sempre em 100%... como fazer isso?

Voce pode montar um preview personalizado usando o componente QuickRep ou pode puxar este exemplo:

arquivo DFM

http://www.bsdg.org/SWAG/DELPHI/0312.PREVIEW.ZIP

Descrição da Unit

Angus Johnson
ajohnson@rpi.net.au

unit Preview;  { dfm file is at end .. use XX34 to decode }

interface

uses
  SysUtils, Classes, Controls, Forms, Quickrep, ExtCtrls, Messages,
  StdCtrls, Buttons, WinTypes, WinProcs, Dialogs, Printers,
  IniFiles;

type
  TFmPreview = class(TForm)
     Panel1: TPanel;
     QRPreview1: TQRPreview;
     Label1: TLabel;
     PrintDialog1: TPrintDialog;
     bbPrev: TBitBtn;
     bbNext: TBitBtn;
     bbZoomOut: TBitBtn;
     bbZoomW: TBitBtn;
     bbZoomIn: TBitBtn;
     bbPrint: TBitBtn;
    bbClose: TBitBtn;
     procedure FormShow(Sender: TObject);
     procedure bbZoomOutClick(Sender: TObject);
     procedure bbZoomWClick(Sender: TObject);
     procedure bbPrevClick(Sender: TObject);
     procedure bbNextClick(Sender: TObject);
     procedure bbPrintClick(Sender: TObject);
     procedure bbZoomInClick(Sender: TObject);
     procedure bbCloseClick(Sender: TObject);
     procedure FormActivate(Sender: TObject);
     procedure FormClose(Sender: TObject; var Action: TCloseAction);
     procedure FormKeyDown(Sender: TObject; var Key: Word;
       Shift: TShiftState);
  private
     procedure CMDialogKey(var message: TCMDialogKey); message CM_DIALOGKEY;
  public
  end;

var
  FmPreview: TFmPreview;

implementation

uses
  Main;

{$R *.DFM}


procedure TFmPreview.FormShow(Sender: TObject);
begin
    QRPreview1.Zoom := 100; {defaults to ZoomIn}
    Label1.caption := 'Page 1 of ' +inttostr(QRPrinter.PageCount);
    if QRPrinter.PageCount = 1 then bbNext.enabled := false
    else bbNext.enabled := true;
    bbClose.setfocus;
    bbZoomIn.enabled := false;
    bbZoomW.enabled := true;
    bbZoomOut.enabled := true;
end;

procedure TFmPreview.bbZoomOutClick(Sender: TObject);
begin
    QRPreview1.ZoomToFit;
    bbZoomOut.enabled := false;
    bbZoomW.enabled := true;
    bbZoomIn.enabled := true;
    bbClose.setfocus;
end;

procedure TFmPreview.bbZoomWClick(Sender: TObject);
begin
    QRPreview1.ZoomToWidth;
    bbZoomW.enabled := false;
    bbZoomOut.enabled := true;
    bbZoomIn.enabled := true;
    bbClose.setfocus;
end;

procedure TFmPreview.bbPrevClick(Sender: TObject);
begin {Previous page}
  if QRPreview1.PageNumber > 1 then
         QRPreview1.PageNumber := QRPreview1.PageNumber-1;
  Label1.caption := 'Page ' + inttostr(QRPreview1.PageNumber)+
                        ' of ' +inttostr(QRPrinter.PageCount);
  bbNext.enabled := true;
  if QRPreview1.PageNumber = 1 then begin
     bbPrev.enabled := false;
     bbNext.setfocus;
  end;
end;

procedure TFmPreview.bbNextClick(Sender: TObject);
begin {Next page}
  if QRPreview1.PageNumber < QRPrinter.PageCount then
                    QRPreview1.PageNumber := QRPreview1.PageNumber+1;
  Label1.caption := 'Page ' + inttostr(QRPreview1.PageNumber)+
                    ' of ' +inttostr(QRPrinter.PageCount);
  bbPrev.enabled := true;
  if QRPreview1.PageNumber = QRPrinter.PageCount then begin
     bbNext.enabled := false;
     bbPrev.setfocus;
  end;
end;

procedure TFmPreview.bbPrintClick(Sender: TObject);
begin
  {A PrintDialog component can be added to the form with an -
  if not PrintDialog1.execute then exit -
  statement placed here.}
  screen.cursor := crHourglass;
  try
     QRPrinter.Print;
     while tag > 1 do begin
       QRPrinter.Print;
       tag := tag-1;
     end;
     tag := 1;
  finally
     screen.cursor := crDefault;
  end;
  close;
end;

procedure TFmPreview.bbZoomInClick(Sender: TObject);
begin
    QRPreview1.Zoom := 100;
    bbZoomIn.enabled := false;
    bbZoomW.enabled := true;
    bbZoomOut.enabled := true;
    bbClose.setfocus;
end;

procedure TFmPreview.bbCloseClick(Sender: TObject);
begin
    close;
end;

procedure TFmPreview.FormActivate(Sender: TObject);
var
  TrayHwnd: HWnd;
  Rect: TRect;
  CxFullScreen, CyFullScreen, CyCaption: integer;
begin
  {size the form to fill the screen...}
  TrayHwnd := FindWindow('Shell_TrayWnd','');
  if TrayHwnd = 0 then {not Win95 screen}
     WindowState := wsMaximized
  else begin
     GetWindowRect(TrayHwnd,Rect);
     CxFullScreen    := GetSystemMetrics(SM_CXFULLSCREEN);
     CyFullScreen    := GetSystemMetrics(SM_CYFULLSCREEN);
     CyCaption       := GetSystemMetrics(SM_CYCAPTION);

     {NOTE: Position must equal either poDefault or poDesigned,
      and WindowState = wsNormal}
     Top      := 0;
     Left     := 0;
     Width    := CxFullScreen;
     Height   := CyFullScreen + CyCaption;

     if (Rect.Top < 0) and (Rect.Left < 0) then begin
       {Taskbar on either top or left}
       if Rect.Right > Rect.Bottom then {Taskbar on top}
         Top  := Rect.Bottom
       else {Taskbar on left}
         Left := Rect.Right;
     end;
  end;
  bbClose.left := width - 76;
  bbPrint.left := width - 144;
end;

procedure TFmPreview.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  QRPreview1.PageNumber := 1; {this is necessary if reopening form!!!?}
  bbPrev.enabled := false;
  QRPreview1.HorzScrollbar.Position := 0;
  QRPreview1.VertScrollbar.Position := 0;
end;

procedure TFmPreview.CMDialogKey(var message: TCMDialogKey);
begin {INTERCEPTS ARROW KEYS INORDER TO MOVE AROUND PAGE}
  with message do
     case CharCode of
       VK_LEFT: begin
         with QRPreview1.HorzScrollbar do Position := Position -50;
         exit;
         end;
        VK_RIGHT: begin
         with QRPreview1.HorzScrollbar do Position := Position +50;
         exit;
         end;
        VK_UP: begin
         with QRPreview1.VertScrollbar do Position := Position -50;
         exit;
         end;
        VK_DOWN: begin
         with QRPreview1.VertScrollbar do Position := Position +50;
         exit;
         end;
     end;
  inherited;
end;

procedure TFmPreview.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin {INTERCEPTS [PG_UP],[PG_DN], [CTRL][PG_UP],[CTRL][PG_DN], [HOME],[END]}
  if (((Key = VK_NEXT) and (Shift = [ssCtrl])) or (Key = VK_END))
                                            and bbNext.enabled then begin
     QRPreview1.PageNumber := QRPrinter.PageCount; {GOTO LAST PAGE}
     Label1.caption := 'Page ' + inttostr(QRPrinter.PageCount)+
                      ' of ' +inttostr(QRPrinter.PageCount);
     bbPrev.enabled := true;
     bbNext.enabled := false;
     bbPrev.setfocus;
     end
  else if (((Key = VK_PRIOR) and (Shift = [ssCtrl])) or (Key = VK_HOME))
                                             and bbPrev.enabled then begin
     QRPreview1.PageNumber := 1; {GOTO FIRST PAGE}
     Label1.caption := 'Page 1' +
                      ' of ' +inttostr(QRPrinter.PageCount);
     bbPrev.enabled := false;
     bbNext.enabled := true;
     bbNext.setfocus;
     end
  else if (Key = VK_NEXT) and bbNext.enabled then bbNextClick(Sender)
  else if (Key = VK_PRIOR) and bbPrev.enabled then bbPrevClick(Sender);
end;

end.

abraço

olá amigo, obrigado pela resposta ao tópico....

entendi essa paradinha de criar personalizado... mas, esse preview pronto, para alterar somente a forma de exibição é possível ou não? é que na verdade esse projeto tem que ser entregue segundona e tem várias coisas ainda pra terminar... ai se tiver como dessa vez iria facilitar...

obrigado pela atenção!

Link para o comentário
Compartilhar em outros sites

  • 0
mas, esse preview pronto, para alterar somente a forma de exibição é possível ou não?

Este é um exemplo de preview com a possibilidade de se alterar o zoom

QRPreview1.Zoom := 100; {defaults to ZoomIn}

procedure TFmPreview.bbZoomInClick(Sender: TObject);
begin
    QRPreview1.Zoom := 200;  // zoom de 200 %
    bbZoomIn.enabled := false;
    bbZoomW.enabled := true;
    bbZoomOut.enabled := true;
    bbClose.setfocus;
end;

voce pode fazer alterações neste código ou criar o seu proprio preview usando este como exemplo

abraço

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,3k
    • Posts
      652,2k
×
×
  • Criar Novo...