Impression stringgrid

Résolu
cs_dugueclin Messages postés 66 Date d'inscription jeudi 2 septembre 2004 Statut Membre Dernière intervention 10 juillet 2012 - 7 mars 2006 à 15:33
DRJEROME Messages postés 436 Date d'inscription jeudi 9 janvier 2003 Statut Membre Dernière intervention 5 février 2015 - 8 mars 2006 à 20:51
bonjour à tous,
Peut-on imprimer la grille d'un stringgrid??.
Si oui, comment?.
en vous remercient d'avance,
Sincères salutation à tous et bon codding.
Dugueclin

2 réponses

cs_Kenavo Messages postés 702 Date d'inscription vendredi 21 mars 2003 Statut Membre Dernière intervention 1 octobre 2009 5
8 mars 2006 à 08:13
Salut,

Je crois qu'il n'y a pas de moyen simple d'imprimer un StringGrid ! Il te faudra ou trouver sur le net un composant grille qui permette l'impression, ou écrire toi-même les procédures qui copient ton StringGrid sur le Canvas de l'objet Printer, ou t'inspirer de celles que j'ai commencé à écrire il y a quelques temps

Ratio est un rapport d'échelle qui peut, pour commencer, être initialisé à (Printer.PageWidth div ClientWidth)

procedure TFormPrtProg.ImprimeGrille(Grid: TStringGrid);
var
i, j: integer;
X, Y, X1, X2, Y1, Y2: real;
begin
Y0 := round(Grid.Top * Ratio);
x0 := Round(Grid.Left * Ratio);
with grid do
begin
Y1 := Y0;
for i := 0 to RowCount - 1 do
Y1 := Y1 + (RowHeights[i] + 1) * Ratio;
Y2 := Y0;
for i := 0 to FixedRows - 1 do
Y2 := Y2 + (RowHeights[i] + 1) * Ratio;
X1 := X0;
for i := 0 to ColCount - 1 do
X1 := X1 + (ColWidths[i] + 1) * Ratio;
X2 := X0;
for i := 0 to FixedCols - 1 do
X2 := X2 + (ColWidths[i] + 1) * Ratio;
end;
Printer.Canvas.Pen.Color := clBlack;
Printer.Canvas.Brush.Color := PColor;
if Grid.FixedRows > 0 then
Printer.Canvas.Rectangle(X0, Y0, round(X1) + 1, round(Y2) + 1);
if Grid.FixedCols > 0 then
Printer.Canvas.Rectangle(X0, Y0, round(X2) + 1, round(Y1) + 1);
with grid do
begin
Printer.Canvas.MoveTo(X0, Y0);
Printer.Canvas.LineTo(round(X1), Y0);
Y := Y0;
if goHorzLine in Grid.Options then
for i := 0 to RowCount - 2 do
begin
Y := Y + (RowHeights[i] + 1) * Ratio;
Printer.Canvas.MoveTo(X0, round(Y));
Printer.Canvas.LineTo(round(X1), round(Y));
end;
Printer.Canvas.MoveTo(X0, round(Y1));
Printer.Canvas.LineTo(round(X1), round(Y1));
end;
with grid do
begin
Printer.Canvas.MoveTo(X0, Y0);
Printer.Canvas.LineTo(X0, round(Y1));
x := X0;
if goVertLine in Grid.Options then
for i := 0 to ColCount - 2 do
begin
x := x + (ColWidths[i] + 1) * Ratio;
Printer.Canvas.MoveTo(round(X), Y0);
Printer.Canvas.LineTo(round(X), round(Y1));
end;
Printer.Canvas.MoveTo(round(X1), Y0);
Printer.Canvas.LineTo(round(X1), round(Y1));
end;
end;

procedure TFormPrtProg.ImprimeValeurs(Grid: TStringGrid);
var
i, j, x, y, Xo, Yo, Xp: integer;
Rect: TRect;
s: string;
begin
Y0 := round(Grid.Top * Ratio);
x0 := Round(Grid.Left * Ratio);
Printer.Canvas.Font := Grid.Font;
Printer.Canvas.Font.Height := round(Grid.Font.Height * Ratio);
X := X0;
for i := 0 to grid.ColCount - 1 do
begin
Y := Y0;
Xo := 5;
for j := 0 to Grid.RowCount - 1 do
begin
Yo := round((Grid.RowHeights[j] * Ratio + Printer.Canvas.Font.Height) / 2);
Rect := Grid.CellRect(i, j);
if (j < grid.FixedRows) or (i < Grid.FixedCols) then
Printer.Canvas.Brush.Color := PColor
else
Printer.Canvas.Brush.Color := clWhite;
s := grid.cells[i, j];
if (s <> '') and Monnaie(s) then
begin
xp := x + round(Grid.ColWidths[i]*ratio) - Yo - Printer.Canvas.TextWidth(grid.cells[i, j]);
Printer.Canvas.TextOut(xp, y + Yo, grid.cells[i, j])
end
else
Printer.Canvas.TextOut(x + Yo, y + Yo, grid.cells[i, j]);
Y := Y + round(Grid.RowHeights[j] * Ratio) + 1;
end;
X := X + round(Grid.ColWidths[i] * Ratio) + 1;
end;
end;

Bon courage

Ken@vo
Code, Code, Codec !

[%3C/body ]
3
DRJEROME Messages postés 436 Date d'inscription jeudi 9 janvier 2003 Statut Membre Dernière intervention 5 février 2015
8 mars 2006 à 20:51
0
Rejoignez-nous