轻松实现DBGrid的多表头计算机等级考试

文章作者 100test 发表时间 2010:01:01 09:35:58
来源 100Test.Com百考试题网


  用法:
  设置DBGrid的Column的Caption属性
  例如:Column1的Caption为111|222
  Column2的Caption为111|333
  那么Column1和Column2公用一个表头111
  unit ADBGrid.
  interface
  uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids, Math.
  type
  TADBGrid = class(TDBGrid)
  private
  { Private declarations }
  //兄弟列子标题,当前列子标题
  BrerLayerTitles, CurLayerTitles: TStringList.
  SaveFont: TFont.
  //根据当前数据列号和表头的层号获取表头的区域
  function TitleLayerRect(LayerTitles: TStrings. TitleRect: TRect. LayerID, ACol: Integer): TRect.
  //解出当前数据列标题为子标题并返回标题层数(子标题数)
  function ExtractSubTitle(LayerTitles: TStrings. ACol: Integer): Integer.
  protected
  { Protected declarations }
  procedure DrawCell(ACol, ARow: Longint. ARect: TRect. AState: TGridDrawState). override.
  procedure Paint. override.
  public
  { Public declarations }
  constructor Create(AOwner: TComponent). override.
  destructor Destroy. override.
  published
  { Published declarations }
  end.
  procedure Register.
  implementation
  procedure Register.
  begin
  RegisterComponents(\Samples\, [TADBGrid]).
  end.
  constructor TADBGrid.Create(AOwner: TComponent).
  begin
  inherited.
  BrerLayerTitles := TStringList.Create.
  curLayerTitles := TStringList.Create.
  SaveFont := TFont.Create.
  end.
  destructor TADBGrid.Destroy.
  begin
  BrerLayerTitles.Free.
  curLayerTitles.Free.
  SaveFont.Free.
  inherited.
  end.
  procedure TADBGrid.DrawCell(ACol, ARow: Integer. ARect: TRect.
  AState: TGridDrawState).
  var
  SubTitleRT, CaptionRt, IndicatorRT: TRect.
  Column: TColumn.
  SubTitle: string.
  i: Integer.
  begin
  if (ARow = 0) and (ACol

相关文章


在Delphi中如何使用RC文件中的字符串表计算机等级考试
计算机二级辅导:如何实现API钩子计算机等级考试
EXE工程和OCX工程的转化计算机等级考试
如何取得系统中的桌面的路径计算机等级考试
轻松实现DBGrid的多表头计算机等级考试
关于读写注册表二进制数据的问题计算机等级考试
在Delphi中捕获控制台程序的输出计算机等级考试
利用剪贴板实现高速导出数据到Excel计算机等级考试
终于可以不用任何控件作出XP风格的程序了计算机等级考试
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛