T
true_afei
Unregistered / Unconfirmed
GUEST, unregistred user!
我想将grid中的内容能按页按一定的缩放比例预览,但不知如何改变字体大小,如何分页及缩入
希望高手能指点一二!
procedure TForm1.Button4Click(Sender: TObject);
const
leftblank=1;
rightblank=1;
topblank=1;
bottomblank=1;
var
pointx,pointy:integer;
printstep:integer;
x,y,i:integer;
s:string;
begin
previewscale:=strtoint(edit1.Text);
pointx:=trunc(GetDeviceCaps(printer.Handle,LOGPIXELSX)/2.54);// div previewscale;
pointy:=trunc(GetDeviceCaps(printer.Handle,LOGPIXELSY)/2.54);// div previewscale;
form2:=Tform2.Create(self);
Form2.Image1.Canvas.Font.Name:='宋体';
form2.Image1.Canvas.Font.Size:=10;
s:='商品信息';
printstep:=Form2.Image1.Canvas.TextHeight(s);
x:=leftblank;
y:=topblank;
if (query1.Active=true) and (query1.RecordCount>0) then
begin
query1.first;
while not query1.eofdo
begin
for i:=0 to DBGrid1.FieldCount-1do
begin
if (x+DBGrid1.Columns.Items.Width)<=(Printer.PageWidth-pointx*rightblank) then
begin
form2.Image1.Canvas.Rectangle(x,y,(x+4+DBGrid1.Columns.items.Width)*pointx,pointy*(y+4+printstep));
if y=topblank then
form2.Image1.Canvas.TextOut(x+2,y+2,DBGrid1.Columns.Title.Caption)
else
form2.Image1.Canvas.TextOut(x+2,y+2,DBGrid1.Fields.AsString);
end;
x:=x+DBGrid1.Columns.Items.Width;
end;
if not (y=pointy*topblank) then
query1.Next;
x:=leftblank;
y:=y+(printstep+8);
end;
application.MessageBox('预览完成','提示',32);
end;
form2.Show;
end;
希望高手能指点一二!
procedure TForm1.Button4Click(Sender: TObject);
const
leftblank=1;
rightblank=1;
topblank=1;
bottomblank=1;
var
pointx,pointy:integer;
printstep:integer;
x,y,i:integer;
s:string;
begin
previewscale:=strtoint(edit1.Text);
pointx:=trunc(GetDeviceCaps(printer.Handle,LOGPIXELSX)/2.54);// div previewscale;
pointy:=trunc(GetDeviceCaps(printer.Handle,LOGPIXELSY)/2.54);// div previewscale;
form2:=Tform2.Create(self);
Form2.Image1.Canvas.Font.Name:='宋体';
form2.Image1.Canvas.Font.Size:=10;
s:='商品信息';
printstep:=Form2.Image1.Canvas.TextHeight(s);
x:=leftblank;
y:=topblank;
if (query1.Active=true) and (query1.RecordCount>0) then
begin
query1.first;
while not query1.eofdo
begin
for i:=0 to DBGrid1.FieldCount-1do
begin
if (x+DBGrid1.Columns.Items.Width)<=(Printer.PageWidth-pointx*rightblank) then
begin
form2.Image1.Canvas.Rectangle(x,y,(x+4+DBGrid1.Columns.items.Width)*pointx,pointy*(y+4+printstep));
if y=topblank then
form2.Image1.Canvas.TextOut(x+2,y+2,DBGrid1.Columns.Title.Caption)
else
form2.Image1.Canvas.TextOut(x+2,y+2,DBGrid1.Fields.AsString);
end;
x:=x+DBGrid1.Columns.Items.Width;
end;
if not (y=pointy*topblank) then
query1.Next;
x:=leftblank;
y:=y+(printstep+8);
end;
application.MessageBox('预览完成','提示',32);
end;
form2.Show;
end;