【问题标题】:How to change selected row's border color and background color of style enabled DBGrid in delphi xe2?如何在delphi xe2中更改启用样式的DBGrid的选定行的边框颜色和背景颜色?
【发布时间】:2014-02-08 06:47:37
【问题描述】:

我在应用程序中使用了默认样式“Amethyst Kamri”。我的 DBgrid 选择的行颜色会根据样式而变化。但我想更改选定行的边框颜色和背景颜色。 我使用 answer of following question. 更改字体样式

https://stackoverflow.com/a/9472000

现在我想改变颜色。如何做到这一点?

【问题讨论】:

    标签: delphi delphi-xe2 tdbgrid


    【解决方案1】:

    您首先需要从 Vcl.DBGrids.TDBGrid 类继承 TDBGrid。并覆盖 Paint 过程。 像这样:

    type
      TDBGrid = class(Vcl.DBGrids.TDBGrid)
      protected
        procedure Paint; override;
      end;
    

    关于 Paint 程序:

    procedure TDBGrid.Paint;
    var
      i, X, Y: Integer;
    begin
      inherited;
      Y := RowHeights[0] + 1;
      X := Width;
      for i := 1 to Self.RowCount - 1 do
      begin
        Y := Y + RowHeights[i] + 1;
        Canvas.Brush.Color := clRed;
        Canvas.FillRect(Rect(0, Y, X, Y + 1));
      end;
    end;
    

    这是最终的结果:

    【讨论】:

    • 我还需要更改slected Row的背景颜色。
    猜你喜欢
    • 2019-10-10
    • 1970-01-01
    • 2018-05-25
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    • 1970-01-01
    • 2011-03-11
    • 2019-06-03
    相关资源
    最近更新 更多