Printing a String Grid D4

What I am trying to do is to exactly replicate what I see in a String Grid on paper, including the spacing as used in the grid eg. the column widths/heights are all exact. Basically the grid will consist of a few tiny squares (Found in the Fixedsys font). I need to position the squares in the cells which I have done but the hard part is being able to get it to print how it looked on the form/grid. Another thing is, should I be using the Draw Grid instead of a String Grid as all I need on the grid are tiny squares to put in a few cells. Are there any Free String\Draw grids available that enables you to print the grid using the correct column spacing etc.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Suggestion: Use Q(uick)report (Delphi standard). There, what you see is what you print and the user gets a standard windows print dialog.

Once I also wanted to print a dbgrid, I did found a dbgrid component with good print-functionality on Torry's pages if I remember correctly.

Suggestion: Use Q(uick)report (Delphi standard). There, what you see is what you print and the user gets a standard windows print dialog.

Once I also wanted to print a dbgrid, I did found a dbgrid component with good print-functionality on Torry's pages if I remember correctly.

heres a couple of ways.
You can print the visible client area of a grid directly:
procedure TForm1.Button1Click(Sender: TObject);
    SetMapMode( printer.canvas.handle, MM_ANISOTROPIC );
                  GetDeviceCaps(canvas.handle, LOGPIXELSX),
                  GetDeviceCaps(canvas.handle, LOGPIXELSY),
                  GetDeviceCaps(printer.canvas.handle, LOGPIXELSX),                   GetDeviceCaps(printer.canvas.handle, LOGPIXELSY),                   Nil);
    stringgrid1.PaintTo( printer.canvas.handle, 100, 100 );
The mapping mode instructions rescale the printer canvas to the same resolution as the screen.

and I got this way from a delphi tip site:
There are several times when I need to send out a quick printout of a
TStringGrid without having to worry
about writting a report for it. There are a couple different ways of
approaching this, we will be looking at
the Delphi function AssignPrn(). Using AssignPrn() we can write to the
printer as if we are writting to a file
using WriteLn(). In this tip we will have to change the printer font to
a fixed width font so our printout will
have straight even columns. We will be using the Delphi functions
Format(), AssignPrn(), WriteLn(),
Rewrite(), and CloseFile().

    For this tip we will need a TButton with a TButton.OnClick event and
a TForm.OnCreate event along
    with a TStringGrid component. You can easily create these events
through the Events tab of the Object
    First we will need to make sure we add Printers to our Units uses
    In our TForm.OnCreate event we will be setting up our TStringGrid
headers which will be the first
    fixed row of the TStringGrid.
    In our TButton.OnClick event we will first set our
TPrinter.PrinterIndex to default printer by setting
    this value to -1.
    Next we will be saving our printers font and resetting it to
'Courier New', a fixed width font. This will
    make our columns print in a straight even line using the Format()
Delphi function.
    Next we will assign our printer textfile to our printer using
    After assigning our file we need to initialize it using Rewrite().
    Before we loop through the TStringGrid rows, we will print out our
header and a row of dashes to
    seperate the header in our printout from the rest of the rows.
    We will use the Delphi function WriteLn() to printout each row to
our assigned printer file. To format
    the rows properly we will use the Delphi function Format() and input
all our columns into a formatted
    Next we will loop through our TStringGrid and printout each row in
the sam fashion as we did with the
    header row.
    Finally we will need to close the file handle we created with
AssignPrn() and rest our printer font to
    its original value..
    Don't forget to type in some text into the TStringGrid before trying
to print :-)
    Format() returns a string formated according to arguments that you
send in. Format() can get quite
    complex. Format looks to add the arguments in the order arranged
into the next position in order
    according to the percent sign "%" in your format string. In other
words, you need as many arguments as
    you have percent signs in your format string parameter. The number
after the percent sign indicates the
    max number of characters that will display. When you add a number, a
period, and a number then this
    indicates that you want to force that number of characters as
percision. In other words if you want two
    characters and your argument only returns one then the return forces
in a leading character whether it be
    a space for a string or a zero "0" for a numeric value. The "s" at
the end of our width and percision
    indicates that our argument will be passing in a string value to be
formated into that position. Take a
    look at the Delphi help file to see all the other values you can
pass in through the argument parameter.
    AssignPrn() assigns a textfile variable to the printer. The only
parameter is the textfile variable.
    Rewrite() creates a new file and opens it. The only parameter is the
assigned textfile variable.
    WriteLn() writes a line of text to our textfile variable. The first
parameter is the string to write. The
    second parameter is the textfile variable to write to.
    CloseFile() gets rid of the association between our textfile and the
printer file. The only parameter is
    our assigned textfile variable.

        Example 1


          TForm1 = class(TForm)
            Button1: TButton;
            StringGrid1: TStringGrid;
            procedure Button1Click(Sender: TObject);
            procedure FormCreate(Sender: TObject);
            { Private declarations }  
            { Public declarations }


        procedure TForm1.FormCreate(Sender: TObject);
          { set our stringgrid to allow editing }
          StringGrid1.Options := StringGrid1.Options +

          { set stringgrid1 to a better height then it's
            normal default }
          StringGrid1.DefaultRowHeight := 20;

          { remove fixed cols }
          StringGrid1.FixedCols := 0;

          { set column count }
          StringGrid1.ColCount := 3;

          { set column headers }
          StringGrid1.Cells[0,0] := 'First Name';
          StringGrid1.Cells[1,0] := 'Last Name';
          StringGrid1.Cells[2,0] := 'Department';

        procedure TForm1.Button1Click(Sender: TObject);
          MyTextFile    : TextFile;
          tmpStr,OldFont : String;
          x              : Integer;
          { set to default printer }
          Printer.PrinterIndex := -1;

          { save the printers old font }
          OldFont := Printer.Canvas.Font.Name;

          { set the printers font name to a fixed
            width font so the printout will have
            even looking columns }
          Printer.Canvas.Font.Name := 'Courier New';

          { assign our textfile to the printer }

            { initialize our textfile }

            { format and print out our header as setup
              in TForm.OnCreate }
            tmpStr := Format('%-20.20s %-20.20s %-20.20s',
            Writeln(MyTextFile, tmpStr);

            { format and print out a seperator between
              the header and rows }
            tmpStr := Format('%-20.20s %-20.20s %-20.20s',
            Writeln(MyTextFile, tmpStr);

            for x := 1 to StringGrid1.RowCount - 1 do
              { format each row and print them out }
              tmpStr := Format('%-20.20s %-20.20s %-20.20s',
              Writeln(MyTextFile, tmpStr);
            { close our textfile }

            { reset the printers font name }
            Printer.Canvas.Font.Name := OldFont;

hope that helps
you could also try TAdvStringGrid from:
Regards Barry

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.