Ich schreibe ein Programm, das unter MAC OS wie auch unter Windows 7 läuft .. laufen soll.
Dabei habe ich eine Seite mit einem Stringgrid, zusätzlich auch einen Titel.
Unter MacOS funktioniert der Ausdruck gut.
Das selbe Programm druckt jedoch unter Windows ganz klein 2,5 x 1,5 cm in der linken oberen Ecke. Dazu habe ich festgestellt, dass das Printer.Canvas.Width und..Height bei Windows 7 Jeweils 0 zurückgibt. Nicht so bei MAC OS. Was muss ich unter Windows berücksichtigen, dass das/der Grid in der Originalgrösse auch ausgedruckt wird ?
Für Hilfe bin ich sehr dankbar.
Hier der Code:
Code: Alles auswählen
procedure TMainWin.BtnPrintProjectGridClick(Sender: TObject);
const
TOTAL_PAGES = 1;
var
page, startPage, endPage: integer;
x,y,i,nWidth,nxPos,nLrand,nRowHeight,nFontPos, nRow , xr: integer;
cTxt: string;
begin
nLrand:=40; // Lft Margin
PrintDialog.Title:='Business Tree';
// Set Orientation
Printer.Orientation := poLandscape;
// Set up print dialog options
printDialog.MinPage := 1; // First allowed page number
printDialog.MaxPage := TOTAL_PAGES; // Highest allowed page number
printDialog.ToPage := TOTAL_PAGES; // 1 to ToPage page range allowed
printDialog.Options := [poPageNums]; // Allow page range selection
// If the user has selected a printer (or default), then print!
if printDialog.Execute then
begin
// Number of copies to print each page
Printer.Copies := printDialog.Copies;
// Start printing
Printer.BeginDoc;
{ ShowMessage('PaperSize.Width '+ intToStr( Printer.PaperSize.Width )
+'Printer.PaperSize.Height = '+intToStr(Printer.PaperSize.Height)
+' PageHeight = '+IntToStr(printer.PageHeight)
+' Canvas.Width = '+IntToStr(Printer.Canvas.Width)
+ ' Canvas.Height = '+IntToStr(Printer.Canvas.Height));}
startPage := printDialog.FromPage;
endPage := printDialog.ToPage;
// Set up the start page number
page := startPage;
// Setup Font
Printer.Canvas.Font.Size:=ProjectGrid.Font.Size;
// Keep printing while all is OK
while (not Printer.Aborted) and Printer.Printing do
begin
// Write out the page number x = linker Rand y = oberer Rand
Printer.Canvas.Font.Color := clBlue;
cTxt:= TxtTabProject.Caption;
Printer.Canvas.TextOut(nLrand,20, cTxt);
cTxt:='eröffnet am: '+' '+ProjectDate.Text;
nxPos:=nLrand+nWidth - Printer.Canvas.TextWidth( ctxt );
Printer.Canvas.TextOut(nxPos,20, cTxt);
x:= nLrand;
y:= 40;
nRow:=0;
nRowHeight:= ProjectGrid.RowHeights[0];
// Set CenterPosition of Text in Cells
nFontPos:= (nRowHeight - abs(Printer.Canvas.Font.Height)) DIV 2;
For nRow:=0 to ProjectGrid.RowCount-1 do
begin
x:= nLrand; // Right Position
Printer.Canvas.Line(x,y,nWidth+nLrand,y); //Horizontal Line
For i:= 0 to ProjectGrid.ColCount-1 do
begin
// Vertical Line per Row
Printer.Canvas.Line(x,y,x,y+nRowHeight);
// Text after Vertical Line
cTxt := ProjectGrid.Rows[nRow][i];
if i < 2 then
begin
Printer.Canvas.TextOut(x+2,y+nFontPos, cTxt)
end
else // Rechtsbündiger Text
begin
xr:= x+ProjectGrid.ColWidths[i];
xr:= xr-Printer.Canvas.TextWidth(cTxt)-2;
Printer.Canvas.TextOut(xr,y+nFontPos, cTxt);
end;
x:=x+ProjectGrid.ColWidths[i];
end;
// Vertical Line at the End of Grid
Printer.Canvas.Line(x,y,x,y+nRowHeight);
y:=y+nRowHeight;
end;
// Last Horizontal Line
x:= nLrand;
Printer.Canvas.Line(x,y,nWidth+nLrand,y);
// Increment the page number
Inc(page);
// Now start a new page - if not the last
if (page <= endPage) and (not Printer.Aborted)
then Printer.NewPage else break;
end;
// Finish printing, start output
Printer.EndDoc;
end;
end;