SQLite3框架

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  i: Integer;
begin
  if gdSelected in State then
    Exit;
  // 定义表头的字体和背景颜色:
  for i := 0 to (Sender as TDBGrid).Columns.Count - 1 do
  begin
    (Sender as TDBGrid).Columns[i].Title.Font.Name := '宋体 '; // 字体
    (Sender as TDBGrid).Columns[i].Title.Font.Size := 9; // 字体大小
    (Sender as TDBGrid).Columns[i].Title.Font.Color := $000000FF; // 字体颜色 ( 红色 )
  //(Sender as TDBGrid).Columns[i].Title.Color := $0000FF00; // 背景色 (绿色 )
  end;
  // 隔行改变网格背景色:
  if (Sender as TDBGrid).DataSource.DataSet.RecNo mod 2 = 0 then
    (Sender as TDBGrid).Canvas.Brush.Color := clInfoBk // 定义背景颜色
  else
    (Sender as TDBGrid).Canvas.Brush.Color := RGB(191, 255, 223); // 定义背景颜色
  // 定义网格线的颜色:
  TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);
  with (Sender as TDBGrid).Canvas do // 画 cell 的边框
  begin
    Pen.Color := $00FF0000; // 定义画笔颜色 (蓝色 )
    MoveTo(Rect.Left, Rect.Bottom); // 画笔定位
    LineTo(Rect.Right, Rect.Bottom); // 画蓝色的横线
    Pen.Color := $0000FF00; // 定义画笔颜色 (绿色 )
    MoveTo(Rect.Right, Rect.Top); // 画笔定位
    LineTo(Rect.Right, Rect.Bottom); // 画绿色的竖线
  end;
end;

 SQLite3框架


 a] 若想标题栏和左边第一列,也 改变 背景色:

DBGrid1.DrawingStyle:=gdsClassic;

b]

DBGrid1.FixedColor:=clInfoBk;


标题栏也自定义字体颜色:

一定要看.dfm里是不是有  Columns,  DBGrid1.DrawingStyle:=gdsClassic;

 

要在DBGrid1没有在界面上显示数据列,直接右键添加空白列,就会出来Columns

    Columns = <
      item
        Expanded = False
        FieldName = 'id'
        Visible = True
      end
      item
        Expanded = False
        FieldName = 'name'
        Visible = True
      end
      item
        Expanded = False
        FieldName = 'info'
        Title.Alignment = taCenter
        Title.Caption = #20449#24687
        Title.Color = clRed
        Title.Font.Charset = DEFAULT_CHARSET
        Title.Font.Color = clMenuHighlight
        Title.Font.Height = -11
        Title.Font.Name = #24188#22278
        Title.Font.Style = [fsBold]
        Visible = True
      end>
 

 总是说我字少。 总是说我字少。 总是说我字少。 总是说我字少。 总