1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
//------------------------------------------------------------------------------
// Gestion impression
//------------------------------------------------------------------------------
procedure TFPhoenix.BtImpDirectClick(Sender: TObject);
begin
PrintGrid(Tabresultat ,2,2);
if ImpDirect then
begin
ImpDirect:=false;
BtImpDirect.FlatStyle:=Fl3D;
BtImpDirect.Begincolor:=Cofonce;
BtImpDirect.Endcolor:=Coclaire;
end
else
begin
ImpDirect:=true;
BtImpDirect.FlatStyle:=FlNone;
BtImpDirect.Begincolor:=Coclaire;
BtImpDirect.Endcolor:=Cofonce;
end;
end;
//------------------------------------------------------------------------------
Function Ech(R:integer):integer;
begin
Ech:=round(R * rapport);
end;
//------------------------------------------------------------------------------
procedure TFPhoenix.PrintGrid(SGrid: TStringGrid ; RF,CF: integer);
var
Nucol : Integer;
TR : TRect;
LargeurCol : array[0..25] of integer;
PosCol : array[0..25] of integer;
Nbligne :integer;
Pscale :integer;
PosLigne :Integer;
HauteurLigne :integer;
PosDepart :integer;
W : real;
largeurTab :Integer;
sortie :TCanvas;
ZoneImpMax :Integer;
ZoneImp :Integer;
SautLigne :Integer;
NuPage :Integer;
MargeDroite,
margeGauche,
MargeHaute,
MargeBasse :integer;
I :integer;
begin
margeGauche:=10;
margeDroite:=5;
MargeHaute:=10;
MargeBasse:=5;
// recalcule la taille du TGrid avec colonne non visible
largeurTab:=MargeGauche;
For Nucol:=0 to sGrid.Colcount-1 do largeurTab:=largeurTab + sGrid.ColWidths[Nucol]; // largeur Grid
largeurTab:=largeurTab+ Margedroite;
W:=printer.PageWidth;
rapport:=W / largeurTab;
ZoneImpMax:=Printer.PageHeight-ech(MargeBasse) ;
//-------------calcul : position et taille colonne en fonction de la destination
For Nucol:=0 to sGrid.Colcount-1 do LargeurCol[Nucol]:=sGrid.ColWidths[Nucol]; // taille colone
PosCol[0]:=margeGauche;
For Nucol:=1 to sGrid.Colcount-1 do PosCol[Nucol]:=PosCol[Nucol-1]+sGrid.ColWidths[Nucol-1]-1; // position des colonnes
For Nucol:=0 to sGrid.Colcount-1 do // adapte le stringGrid a la destinatino
begin
LargeurCol[Nucol]:=Ech(LargeurCol[Nucol]);
posCol[Nucol]:=Ech(posCol[Nucol]);
end;
For I:=1 to sGrid.Rowcount-1 do Sgrid.RowHeights[i] :=Sgrid.RowHeights[i]+2;
printer.BeginDoc ;
Nupage:=0;
with printer.canvas do
begin
// dessine titre + cadre
Brush.Color := clBlack;
Pen.Color:=clblack;
Font.Name:='Arial';
Brush.Color := clwhite;
SautLigne :=Sgrid.RowHeights[1];
Font.Height:=-ech(Sgrid.RowHeights[1] div 2);
PosDepart:=SautLigne;
Font.Style:=[fsBold, fsUnderline];
TextOut(ech(margeGauche*2),ech(PosDepart), labelChemin1.caption +' - '+MesTest10+intTostr(Nupage+1));
Font.Style:=[];
PosLigne:=PosDepart+SautLigne;
ZoneImp:=PosLigne;
Pscale:=PosLigne;
HauteurLigne:=Pscale+Sgrid.RowHeights[1]+1;
For Nbligne:=1 to sGrid.RowCount-1 do // imprime ligne par ligne
begin
For Nucol:=0 to sGrid.ColCount-1 do
begin
if (Nucol < Cf) or (Nbligne < Rf) then Brush.Color:=clsilver
else Brush.Color := clwhite;
TR:=Rect(PosCol[Nucol], ech(PosLigne),PosCol[Nucol]+LargeurCol[Nucol], Ech(HauteurLigne));
TextRect(TR,PosCol[Nucol]+ech(4),ech(PosLigne)+ech(2), sGrid.Cells[Nucol,NbLigne]);
Brush.Color := clBlack;
FrameRect(TR);
end;
PosLigne:=HauteurLigne-1;
HauteurLigne:=PosLigne+Sgrid.RowHeights[Nbligne+1];
ZoneImp:=ech(HauteurLigne);
if ZoneImp > (ZoneImpMax-ech(Sgrid.RowHeights[Nbligne+1])) then
begin
Brush.Color := clwhite;
TextOut(100,ZoneImp-Font.Size,MesTest9);
Brush.Color := clblack;
Printer.NewPage;
Inc(Nupage);
PosDepart:=SautLigne;
Brush.Color := clwhite;
TextOut(ech(margeGauche*2),ech(PosDepart), MesTest11 +labelChemin1.caption +' - '+ MesTest10 +intTostr(Nupage+1));
Brush.Color := clblack;
PosLigne:=PosDepart+SautLigne;
ZoneImp:=PosLigne;
Pscale:=PosLigne;
HauteurLigne:=Pscale+Sgrid.RowHeights[1]+1;
end;
end;
Brush.Color := clwhite;
TextOut(ech(margeGauche*2) ,ech(PosLigne)+ech(2), labelChemin1.caption+' - ' + MesTest12 );
end;
Printer.EndDoc ;
For I:=1 to sGrid.Rowcount-1 do Sgrid.RowHeights[i] :=Sgrid.RowHeights[i]-2;
end; |
Partager