delphi : how can I change color of a cell in string grid

前端 未结 3 1781
囚心锁ツ
囚心锁ツ 2020-12-07 01:13

I want to change background color ( not font ) of a cell in string grid in delphi .

Just one cell not a row or a column.

Can I?


RRUZ : your pro

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 01:32

    The Rafael link contains all which you need, using the OnDrawCell event is the way to paint the cells of a StrignGrid. check this sample which paint only the background of an specific cell.

    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;  Rect: TRect; State: TGridDrawState);
    begin
      if (ACol = 3) and (ARow = 2) then
        with TStringGrid(Sender) do
        begin
          //paint the background Green
          Canvas.Brush.Color := clGreen;
          Canvas.FillRect(Rect);
          Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[ACol, ARow]);
        end;
    end;
    

提交回复
热议问题