Re:Color of grid lines
Quote
> Can anyone help, how can I set the line color of a grid ?
Unfortunately, these colors are hardcoded in the Paint method of
TCustomGrid.
One thing you can do is to draw the grid lines yourself in the OnDrawCell
event. Turn off the grid lines by setting goFixedVertLines,
goFixedHorzLines, goVertLines, goHorzLines to False in the 'Options'
property, set DefaultDrawing to False and use this OnDrawCell event handler:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
aStringGrid: TStringGrid;
function IsButton: boolean;
begin
Result := (aCol<aStringGrid.FixedCols) or
(aRow<aStringGrid.FixedRows);
end;
begin
aStringGrid := Sender as TStringGrid;
with aStringGrid.canvas do
begin
if IsButton then
pen.color := clBlue
else
pen.color := clRed;
dec(Rect.Right);
dec(Rect.Bottom);
moveto(rect.right,rect.top);
lineto(rect.right,rect.bottom);
lineto(rect.left-1,rect.bottom);
if isButton then
begin
DrawFrameControl(aStringGrid.canvas.Handle,Rect,DFC_BUTTON,DFCS_BUTTONPUSH);
Font.Color := clBlack;
SetBkMode(handle,TRANSPARENT);
TextOut(Rect.Left+2,Rect.Top+2,aStringGrid.Cells[aCol,aRow]);
end
else
begin
if gdSelected in State then
begin
Brush.color := clHighlight;
Font.Color := clHighlightText;
end
else
begin
Brush.color := aStringGrid.Color;
Font.Color := aStringGrid.Font.Color;
end;
TextRect(Rect,Rect.Left+2,Rect.Top+2,aStringGrid.Cells[aCol,aRow]);
end;
end;
end;
Charles