【问题标题】:delphi 7: How to update StringGrid cells color dependence on a state of boolean variabledelphi 7:如何更新 StringGrid 单元格颜色对布尔变量状态的依赖性
【发布时间】:2016-06-30 09:15:25
【问题描述】:

我想要:如果布尔变量设置为 true,StringGrid 中的单元格(错误消息)是否应该是红色的。它不能自动与 OnDrawCell 一起使用。 我怎样才能实现它?提前致谢。

【问题讨论】:

    标签: delphi events binding tstringgrid


    【解决方案1】:

    OnDrawCell 事件中,检查布尔变量的状态,如果要绘制正确的单元格,则将颜色设置为红色。

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

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

    当布尔值的状态发生变化时,只需调用MyStringGrid.RepaintMyStringGrid.Invalidate即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-04
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 2019-09-07
      相关资源
      最近更新 更多