Recent

Author Topic: What print component palette to print a dbgrid(solved)  (Read 9136 times)

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
What print component palette to print a dbgrid(solved)
« on: October 15, 2010, 12:32:17 am »
What print component palette to print a dbgrid?
or any code that would print a dbgrid?


Thanks
« Last Edit: October 22, 2010, 12:59:37 am by xenablaise »

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: What print component palette to print a dbgrid
« Reply #1 on: October 15, 2010, 12:51:39 am »
I got this code BUT it prints very very small, like 0.5 font size.
How do I make the font size 12 or 14?


function MulDiv(nNumber, nNumerator, nDenominator: Integer): Integer;
begin
  Result:=Round(int64(nNumber)*int64(nNumerator)/nDenominator);
end;

procedure TForm1.BTNprintClick(Sender: TObject);
const
  LeftMargin = 0.05;
  TopMargin = 0.05;
  BottomMargin = 0.05;
var
  i: integer;
  x,y: integer;
begin
  if PrintDialog1.Execute then
    begin
    Printer.BeginDoc;
    y := Round(TopMargin*Printer.PageHeight);
    DBGridPrintMember.DataSource.DataSet.First;
    while not DBGridPrintMember.DataSource.DataSet.Eof do
      begin
      x := Round(LeftMargin*Printer.PageWidth);
      for i := 0 to DBGridPrintMember.DataSource.DataSet.FieldCount-1 do
        begin
        printer.Canvas.TextOut(x,y,DBGridPrintMember.DataSource.DataSet.Fields.AsString);
        x := x + MulDiv(DBGridPrintMember.Columns.Width,Printer.PageWidth, DBGridPrintMember.Width);
        end;
      DBGridPrintMember.DataSource.DataSet.Next;
      y := y + printer.Canvas.TextHeight('A');
      if y > (1-TopMargin-BottomMargin)* Printer.PageHeight then
        begin
        y := Round(TopMargin*Printer.PageHeight);
        Printer.NewPage;
        end;
      end;
    Printer.EndDoc;
    end;
end;

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: What print component palette to print a dbgrid
« Reply #2 on: October 15, 2010, 01:27:41 am »
Got it by:
Printer.Canvas.Font.Height := 78;

But is that right?
or else?

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: What print component palette to print a dbgrid
« Reply #3 on: October 15, 2010, 07:56:03 am »
Got it by:
Printer.Canvas.Font.Height := 78;

But is that right?
or else?

Try
Printer.Canvas.Font.Size := 12; //Example

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: What print component palette to print a dbgrid
« Reply #4 on: October 15, 2010, 11:31:15 am »
No errors. its fine.

I hope the code works fine too.

I wonder why these is not included in lazarus tdbgrid, the printbox property, the sort things.  In just a matter of minutes they can mix up this functions to the tdbgrid.

anyway I hope they heard me. lol


Thank a lot.

jesusr

  • Sr. Member
  • ****
  • Posts: 499
Re: What print component palette to print a dbgrid
« Reply #5 on: October 21, 2010, 11:56:59 pm »
In LazReport Tab there is a component specifically to print a dbgrid, see components/lazreport/samples/editor demo for a demonstration.

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: What print component palette to print a dbgrid(solve)
« Reply #6 on: October 22, 2010, 12:52:17 am »
Thank you,
I already know that
 :D

 

TinyPortal © 2005-2018