JustinWillis
asked on
StringGrid.Paintto size prob
Hello, I am trying to do something which I though would be very simple but I can't get it to work..
I have a stringgrid about 500w by 150h, 7 rows and 3 cols but I don't think this is relevant. I am trying to send it to the printer using the following, Data being the TStringGrid...
procedure TForm1.Button1Click(Sender : TObject);
var i:integer;
begin
with Printer do
begin
BeginDoc;
Printer.PageWidth := 400;
Data.PaintTo(Handle, 10, 10);
EndDoc;
end;
end;
My problem is that this prints it very very small in the top left corner, the scale is all wrong, is this something to do with the DPI setting of the printer? how do I change the output size? is this done with TPrinter or the TStringGrid?
Thanks for any help!
JustinWillis.
I have a stringgrid about 500w by 150h, 7 rows and 3 cols but I don't think this is relevant. I am trying to send it to the printer using the following, Data being the TStringGrid...
procedure TForm1.Button1Click(Sender
var i:integer;
begin
with Printer do
begin
BeginDoc;
Printer.PageWidth := 400;
Data.PaintTo(Handle, 10, 10);
EndDoc;
end;
end;
My problem is that this prints it very very small in the top left corner, the scale is all wrong, is this something to do with the DPI setting of the printer? how do I change the output size? is this done with TPrinter or the TStringGrid?
Thanks for any help!
JustinWillis.
This will print data from the columns and rows, but do you need gridlines as well?
Are you looking for a screenshot print really?
procedure PrintGrid(sGrid: TStringGrid; sTitle: String);
var
X1, X2 : Integer;
Y1, Y2 : Integer;
TmpI : Integer;
F : Integer;
TR : TRect;
begin
Printer.Title:=sTitle;
Printer.BeginDoc;
Printer.Canvas.Pen.Color:= 0;
Printer.Canvas.Font.Name:= 'Times New Roman';
Printer.Canvas.Font.Size:= 12;
Printer.Canvas.Font.Style: =[fsBold, fsUnderline];
Printer.Canvas.TextOut(0, 100, Printer.Title);
For F:=1 to sGrid.ColCount-1 do begin
X1:=0;
For TmpI:=1 to (F-1) do
X1:=X1+5*(sGrid.ColWidths[ TmpI]);
Y1:=300;
X2:=0;
For TmpI:=1 to F do
X2:=X2+5*(sGrid.ColWidths[ TmpI]);
Y2:=450;
TR:=Rect(X1, Y1, X2-30, Y2);
Printer.Canvas.Font.Style: =[fsBold];
Printer.Canvas.Font.Size:= 7;
Printer.Canvas.TextRect(TR , X1+50, 350, sGrid.Cells[F, 0]);
Printer.Canvas.Font.Style: =[];
For TmpI:=1 to sGrid.RowCount-1 do begin
Y1:=150*TmpI+300;
Y2:=150*(TmpI+1)+300;
TR:=Rect(X1, Y1, X2-30, Y2);
Printer.Canvas.TextRect(TR , X1+50, Y1+50, sGrid.Cells[F, TmpI]);
end;
end;
Printer.EndDoc;
end;
Are you looking for a screenshot print really?
procedure PrintGrid(sGrid: TStringGrid; sTitle: String);
var
X1, X2 : Integer;
Y1, Y2 : Integer;
TmpI : Integer;
F : Integer;
TR : TRect;
begin
Printer.Title:=sTitle;
Printer.BeginDoc;
Printer.Canvas.Pen.Color:=
Printer.Canvas.Font.Name:=
Printer.Canvas.Font.Size:=
Printer.Canvas.Font.Style:
Printer.Canvas.TextOut(0, 100, Printer.Title);
For F:=1 to sGrid.ColCount-1 do begin
X1:=0;
For TmpI:=1 to (F-1) do
X1:=X1+5*(sGrid.ColWidths[
Y1:=300;
X2:=0;
For TmpI:=1 to F do
X2:=X2+5*(sGrid.ColWidths[
Y2:=450;
TR:=Rect(X1, Y1, X2-30, Y2);
Printer.Canvas.Font.Style:
Printer.Canvas.Font.Size:=
Printer.Canvas.TextRect(TR
Printer.Canvas.Font.Style:
For TmpI:=1 to sGrid.RowCount-1 do begin
Y1:=150*TmpI+300;
Y2:=150*(TmpI+1)+300;
TR:=Rect(X1, Y1, X2-30, Y2);
Printer.Canvas.TextRect(TR
end;
end;
Printer.EndDoc;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot Mike, thats great. Didn't print in colour though, not really a requirement but may be nice to know how to do this in future, if I figure that out I will post amended code. The Paintto method I was trying to use seems to print wysiwyg which is perfect but the scale is just all wrong, oh well I guess that would just be too easy huh?
Thanks again!
JustinWillis.
Thanks again!
JustinWillis.
hmm,
i would use paintto to paint on a temporary bitmap-object,
and then do a stretchdraw or bitblt to the printercanvas
just as an alternative
meikl ;-)
i would use paintto to paint on a temporary bitmap-object,
and then do a stretchdraw or bitblt to the printercanvas
just as an alternative
meikl ;-)
ASKER
Oh of course, why didn't I think of that, seems so obvious now.
Many thanks guys, will come in handy.
JustinWillis.
Many thanks guys, will come in handy.
JustinWillis.
ASKER