Это не очень сложно, но проблемки, скорей всего, могут появиться. Набросок:
DFM
object Form1: TForm1
Left = 240
Top = 113
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
ParentFont = True
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 18
Top = 9
Width = 607
Height = 211
DataSource = DataSource1
TabOrder = 0
end
object DataSource1: TDataSource
DataSet = Table1
Left = 333
Top = 225
end
object Table1: TTable
Active = True
DatabaseName = 'DBDEMOS'
TableName = 'biolife.db'
Left = 354
Top = 252
end
end
PAS
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
DB, DBTables, Grids, DBGrids;
type
TDBGrid = class(DBGrids.TDBGrid)
private
FBmp: TBitmap;
protected
procedure Scroll(Distance: Integer); override;
procedure Paint; override;
procedure DrawColumnCell(const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Table1: TTable;
private
public
end;
var
Form1: TForm1;
implementation
constructor TDBGrid.Create(AOwner: TComponent);
begin
inherited;
FBmp := TBitmap.Create;
FBmp.LoadFromFile('MyBmp.bmp');
end;
destructor TDBGrid.Destroy;
begin
FBmp.Free;
inherited;
end;
procedure TDBGrid.DrawColumnCell(const Rect: TRect; DataCol: Integer;
Column: TColumn; State: TGridDrawState);
var
Value: String;
R: TRect;
begin
Windows.BitBlt(Canvas.Handle, Rect.Left, Rect.Top, Rect.Right, Rect.Bottom, FBmp.Canvas.Handle, Rect.Left, Rect.Top, SRCCOPY);
Canvas.Brush.Style := bsClear;
R := Rect;
Value := Column.Field.AsString;
DrawText(Canvas.Handle, PChar(Value), Length(Value), R, DT_LEFT or DT_VCENTER);
inherited;
end;
procedure TDBGrid.Paint;
var
DrawInfo: TGridDrawInfo;
begin
CalcDrawInfo(DrawInfo);
inherited;
with DrawInfo do
begin
if Horz.GridBoundary < Horz.GridExtent then
begin
Windows.BitBlt(Canvas.Handle, Horz.GridBoundary, 0, Horz.GridExtent, Vert.GridBoundary, FBmp.Canvas.Handle,
Horz.GridBoundary, 0, SRCCOPY);
end;
if Vert.GridBoundary < Vert.GridExtent then
begin
Windows.BitBlt(Canvas.Handle, 0, Vert.GridBoundary, Horz.GridExtent, Vert.GridExtent, FBmp.Canvas.Handle,
0, Vert.GridBoundary, SRCCOPY);
end;
end;
end;
procedure TDBGrid.Scroll(Distance: Integer);
begin
inherited;
InvalidateRect(Handle, nil, False);
end;
end.
|