unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls;
type
//هنا للتعديل على المكون TDBGrid الأصلي
TDBGrid = class(DBGrids.TDBGrid)
private
FTitleHeight: Integer;
FTitleFlat: Boolean; // bonus property
procedure SetTitleHeight(Value: Integer);
procedure SetTitleFlat(Value: Boolean);
protected
public
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
published
constructor Create(AOwner: TComponent); override;
property TitleHeight: Integer read FTitleHeight write SetTitleHeight;
property TitleFlat: Boolean read FTitleFlat write SetTitleFlat;
end;
TForm1 = class(TForm)
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TDBGrid }
constructor TDBGrid.Create(AOwner: TComponent);
begin
Inherited;
FTitleHeight := 32;
end;
procedure TDBGrid.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
var
S: String;
C: TColumn;
F: Integer;
begin
F := 0;
RowHeights[0] := FTitleHeight;
if (ARow = 0) and ((ACol > 0) or not (dgIndicator in Options)) and
(ColCount > 0) then
begin
if not FTitleFlat then
begin
Inherited;
InflateRect(ARect, -1, -1);
end;
C := Columns[ACol - Integer(dgIndicator in Options)];
S := C.Title.Caption;
Canvas.Font := C.Font;
Canvas.FillRect(ARect);
case C.Title.Alignment of
taLeftJustify: F := DT_LEFT;
taCenter: F:= DT_CENTER;
taRightJustify: F := DT_RIGHT;
end;
F := F + DT_WORDBREAK;
InflateRect(ARect, -1, -1);
DrawText(Canvas.Handle, PChar(S), Length(S), ARect, F);
end
else
Inherited;
end;
procedure TDBGrid.SetTitleHeight(Value: Integer);
begin
FTitleHeight := Value;
RowHeights[0] := Value;
end;
procedure TDBGrid.SetTitleFlat(Value: Boolean);
begin
FTitleFlat := Value;
Invalidate;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
DBGrid1.Columns[1].Title.Caption := 'First Line'+#13#10+'Second Line';
end;
end.