S
super-ljc
Unregistered / Unconfirmed
GUEST, unregistred user!
经过上网查找终于找到能打印stringgrid的源码 由于我不懂打印知识 不知怎样调解为每列按实际列宽度我发现打出来宽度是平均的 那位高手给我修改一下使打出来和实际一样 ;
如第一列长为40 字符 2列是12字符 请指教 以下为源码 请一定告我是如何作的源码!
procedure printstringgrid(stringgrid: TbsSkinStringGrid;
caption: string;
rq: tdatetime);
var
i, j, m, k, n, w, y, p: integer;
PointX, PointY, LCount, RCount, CX, CY, Widthw, Heightw: integer;
year, month, day, hour, min, sec, hsec: word;
date, time: string;
collen: array[0..6] of integer;
//我加的想改变其列宽
begin
n := 0;
collen[0]:=0;
collen[1]:=30;
collen[2]:=-20;
collen[3]:=30;
collen[4]:=-20;
collen[5]:=10;
collen[6]:=-10;
decodedate(rq, year, month, day);
decodetime(now, hour, min, sec, hsec);
date := inttostr(year) + '年' + inttostr(month) + '月' + inttostr(day) + '日';
time := inttostr(hour) + '时' + inttostr(min) + '分' + inttostr(sec) + '秒 ';
n := application.MessageBox('确实要打印吗?', ' 打印提示', 3);
if n <> 6 then
exit;
PointX := GetDeviceCaps(printer.Handle, LOGPIXELSX) div 3;
PointY := GetDeviceCaps(printer.Handle, LOGPIXELSY) div 3;
m := GetDeviceCaps(printer.handle, LOGPIXELSX) div 3;
n := 0;
printer.begin
Doc;
CX := trunc(PointX * 1.5);
CY := PointY * 3;
widthw := (printer.PageWidth - cx) div stringgrid.ColCount;
printer.Canvas.Pen.Width := 15;
printer.Canvas.Font.Size := 20;
printer.Canvas.Font.Name := '楷体_GB2312';
printer.Canvas.TextOut(printer.PageWidth div 3, m, caption);
printer.Canvas.Pen.Width := 2;
printer.Canvas.Font.Size := 10;
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
//printer.Canvas.TextOut(widthw, pointy + m + cx div 4, date);
printer.Canvas.TextOut((stringgrid.ColCount - 2) * widthw, pointy + m + cx div 4, date);
for i := 0 to stringgrid.RowCount - 2do
begin
for j := 0 to stringgrid.ColCount - 1do
begin
if (PointX = GetDeviceCaps(printer.Handle, LOGPIXELSX) div 3) and (PointY = GetDeviceCaps(printer.Handle, LOGPIXELSY) div 3) and (n = 1) then
begin
printer.Canvas.Pen.Width := 15;
printer.Canvas.Font.Size := 20;
printer.Canvas.Font.Name := '楷体_GB2312';
printer.Canvas.TextOut(printer.PageWidth div 3, m, caption);
printer.Canvas.Pen.Width := 2;
printer.Canvas.Font.Size := 10;
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
//printer.Canvas.TextOut(widthw, pointy + m + cx div 4, date);
printer.Canvas.TextOut((stringgrid.ColCount - 2) * widthw, pointy + m + cx div 4, date);
for w := 0 to stringgrid.ColCountdo
begin
printer.Canvas.TextOut(pointx + widthw * w, pointy + m + m + m div 3, '' + stringgrid.Cells[w, 0]);
printer.Canvas.MoveTo(pointx + widthw * w, pointy + 2 * m);
printer.Canvas.LineTo(pointx + widthw * w, pointy + m * 3);
end;
pointy := pointy + m;
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
end;
printer.Canvas.TextOut(pointx + widthw * j, pointy + m + m + m div 3, stringgrid.Cells[j, i]);
printer.Canvas.MoveTo(pointx + widthw * j, pointy + 2 * m);
printer.Canvas.LineTo(pointx + widthw * j, pointy + m * 3);
end;
printer.Canvas.MoveTo(pointx + widthw * j, pointy + 2 * m);
printer.Canvas.LineTo(pointx + widthw * j, pointy + m * 3);
pointy := pointy + m;
if pointy + m > printer.PageHeight - 2 * cx then
begin
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
PointX := GetDeviceCaps(printer.Handle, LOGPIXELSX) div 3;
PointY := GetDeviceCaps(printer.Handle, LOGPIXELSY) div 3;
n := 1;
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
printer.Canvas.TextOut(printer.PageWidth div 2 - cx, printer.PageHeight - cx div 4, '第 ' + inttostr(printer.PageNumber) + ' 页');
printer.NewPage;
end;
PointX := GetDeviceCaps(printer.Handle, LOGPIXELSX) div 3;
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
end;
printer.Canvas.TextOut(printer.PageWidth div 2 - cx, printer.PageHeight - cx div 4, '第 ' + inttostr(printer.PageNumber) + ' 页');
printer.EndDoc;
end;
如第一列长为40 字符 2列是12字符 请指教 以下为源码 请一定告我是如何作的源码!
procedure printstringgrid(stringgrid: TbsSkinStringGrid;
caption: string;
rq: tdatetime);
var
i, j, m, k, n, w, y, p: integer;
PointX, PointY, LCount, RCount, CX, CY, Widthw, Heightw: integer;
year, month, day, hour, min, sec, hsec: word;
date, time: string;
collen: array[0..6] of integer;
//我加的想改变其列宽
begin
n := 0;
collen[0]:=0;
collen[1]:=30;
collen[2]:=-20;
collen[3]:=30;
collen[4]:=-20;
collen[5]:=10;
collen[6]:=-10;
decodedate(rq, year, month, day);
decodetime(now, hour, min, sec, hsec);
date := inttostr(year) + '年' + inttostr(month) + '月' + inttostr(day) + '日';
time := inttostr(hour) + '时' + inttostr(min) + '分' + inttostr(sec) + '秒 ';
n := application.MessageBox('确实要打印吗?', ' 打印提示', 3);
if n <> 6 then
exit;
PointX := GetDeviceCaps(printer.Handle, LOGPIXELSX) div 3;
PointY := GetDeviceCaps(printer.Handle, LOGPIXELSY) div 3;
m := GetDeviceCaps(printer.handle, LOGPIXELSX) div 3;
n := 0;
printer.begin
Doc;
CX := trunc(PointX * 1.5);
CY := PointY * 3;
widthw := (printer.PageWidth - cx) div stringgrid.ColCount;
printer.Canvas.Pen.Width := 15;
printer.Canvas.Font.Size := 20;
printer.Canvas.Font.Name := '楷体_GB2312';
printer.Canvas.TextOut(printer.PageWidth div 3, m, caption);
printer.Canvas.Pen.Width := 2;
printer.Canvas.Font.Size := 10;
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
//printer.Canvas.TextOut(widthw, pointy + m + cx div 4, date);
printer.Canvas.TextOut((stringgrid.ColCount - 2) * widthw, pointy + m + cx div 4, date);
for i := 0 to stringgrid.RowCount - 2do
begin
for j := 0 to stringgrid.ColCount - 1do
begin
if (PointX = GetDeviceCaps(printer.Handle, LOGPIXELSX) div 3) and (PointY = GetDeviceCaps(printer.Handle, LOGPIXELSY) div 3) and (n = 1) then
begin
printer.Canvas.Pen.Width := 15;
printer.Canvas.Font.Size := 20;
printer.Canvas.Font.Name := '楷体_GB2312';
printer.Canvas.TextOut(printer.PageWidth div 3, m, caption);
printer.Canvas.Pen.Width := 2;
printer.Canvas.Font.Size := 10;
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
//printer.Canvas.TextOut(widthw, pointy + m + cx div 4, date);
printer.Canvas.TextOut((stringgrid.ColCount - 2) * widthw, pointy + m + cx div 4, date);
for w := 0 to stringgrid.ColCountdo
begin
printer.Canvas.TextOut(pointx + widthw * w, pointy + m + m + m div 3, '' + stringgrid.Cells[w, 0]);
printer.Canvas.MoveTo(pointx + widthw * w, pointy + 2 * m);
printer.Canvas.LineTo(pointx + widthw * w, pointy + m * 3);
end;
pointy := pointy + m;
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
end;
printer.Canvas.TextOut(pointx + widthw * j, pointy + m + m + m div 3, stringgrid.Cells[j, i]);
printer.Canvas.MoveTo(pointx + widthw * j, pointy + 2 * m);
printer.Canvas.LineTo(pointx + widthw * j, pointy + m * 3);
end;
printer.Canvas.MoveTo(pointx + widthw * j, pointy + 2 * m);
printer.Canvas.LineTo(pointx + widthw * j, pointy + m * 3);
pointy := pointy + m;
if pointy + m > printer.PageHeight - 2 * cx then
begin
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
PointX := GetDeviceCaps(printer.Handle, LOGPIXELSX) div 3;
PointY := GetDeviceCaps(printer.Handle, LOGPIXELSY) div 3;
n := 1;
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
printer.Canvas.TextOut(printer.PageWidth div 2 - cx, printer.PageHeight - cx div 4, '第 ' + inttostr(printer.PageNumber) + ' 页');
printer.NewPage;
end;
PointX := GetDeviceCaps(printer.Handle, LOGPIXELSX) div 3;
printer.Canvas.MoveTo(pointx, pointy + m * 2);
printer.Canvas.LineTo((widthw + cx div 15) * (stringgrid.ColCount), pointy + m * 2);
end;
printer.Canvas.TextOut(printer.PageWidth div 2 - cx, printer.PageHeight - cx div 4, '第 ' + inttostr(printer.PageNumber) + ' 页');
printer.EndDoc;
end;