鼠标点中一个CELL后,背景色变为兰色,如何修改成其他颜色?同时,如何修改这个单元格的字体颜色?
在选中其他CELL时,该格子配色自动还原。

解决方案 »

  1.   

    在 canves对象的BrushCropy方法!
    procedure BrushCopy(const Dest:TRect;Bitmap:TBitmap;const Source:TRect;Color:Tcolor)
      

  2.   

    利用DBgrid的OnDrawColumnCell事件。
      

  3.   

    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
      with TDBGrid(Sender) do
      begin
        {case Self.ADOQuery1.RecNo Mod 2 of
          0: Canvas.Brush.Color :=clMoneyGreen;
          1: Canvas.Brush.Color :=clWindow;
        end;}  //这个是该背景色的,不是高亮色
        if gdSelected in State then
        begin
          //Canvas.Font.Color :=clBackground;  //这个是改字体色的
          Canvas.Brush.Color:=clSkyBlue;  //改高亮色
          Canvas.FillRect(Rect);
        end;
        DefaultDrawColumnCell(Rect,DataCol,Column,State);
      end;
    end;