10

我只是想使用delphi XE,在此之前我一直是Delphi7的忠实粉丝。
我看到新的 dbgrid 允许使用主题和渐变样式。

我正在使用渐变并设置行选择,它具有用于列标题的渐变开始和结束属性。
但是要设置的属性在selected color哪里?
这很奇怪,因为颜色不匹配,selected color总是蓝色渐变。

我可以做到这一点customdraw,我只想知道是否有任何方法可以在没有自定义绘图的情况下进行更改。

4

1 回答 1

1

所选颜色来自操作系统。
在那里它被编码为clHighlight.

您不能这样更改它,但您可以子类化 dbgrid 并覆盖 DrawCell 方法。
或者更容易添加onDrawCell事件处理程序。

procedure TForm1.DBGrid1DrawCell(Sender: TObject, const Rect: TRect; Field: TField;  State: TGridDrawState); 
var
  index: Integer;
begin
  if not(gdSelected in State) then DefaultDrawCell(Rect, Field, State)
  else begin 
    index := ARow * DBGrid1.ColCount + ACol;
    DBGrid1.Canvas.Brush.Color := clYellow; <<-- some color  
    DBGrid1.Canvas.FillRect(Rect);
    if (gdFocused in State) then begin
      DBGrid1.Canvas.DrawFocusRect(Rect);
    end;
    ImageList1.Draw(DBGrid1.Canvas,Rect.Left,Rect.Top,index, True);
end;
于 2013-03-20T17:36:52.833 回答