Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

darker lines in a StringGrid

Status
Not open for further replies.

tamara3776

Programmer
Apr 6, 2004
18
US
Hey,
I am not even sure if this is possible or not. I was wondering if there is a way to have the grid lines in a string grid show as black and not the standard grey.

Any help would be appreciated.
Thanks
 
I've had a quick go and it's harder than it looks!!

You need to first set the DefaultDrawing property of the grid to false to stop the grid automatically painting the cells.

You then need to add something like the following code into the grid's OnDrawCell event, which is called every time a cell in the grid needs painting:
Code:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  with StringGrid1 do
  begin
    if gdFixed in State then
      Canvas.Brush.Color := FixedColor // if fixed cell then use the fixed colour
    else
      Canvas.Brush.Color := Color;
    Canvas.Pen.Color   := clBlack;
    // paint the cell
    Canvas.Rectangle(Rect.Left, Rect.Top, Rect.Right + GridLineWidth, Rect.Bottom + GridLineWidth);
    // output cell text
    DrawText(Canvas.Handle,
             PChar(Cells[ACol, ARow]),
             Length(Cells[ACol, ARow]),
             Rect,
             DT_CENTER Or DT_NOPREFIX Or DT_WORDBREAK Or DT_EXTERNALLEADING);

  end;
end;


Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top