其实delphi的帮助里也非常清楚,drawcell事件的帮助原文大意如下
以下代码在drawgrid的每个cell中绘制存储于imagelist1元件中的位图,当某个
cell得到焦点后,在这个cell上画一个边框做标示,cell就是你的drawgrid中的
每个网格。
procedure TForm1.DrawGrid1DrawCell(Sender: TObject; aCol, aRow: Longint;
Rect: TRect; State: TGridDrawState);
var
index: integer;
begin
index := Row * DrawGrid1.ColCount + Col;
with Sender as TDrawGrid do
begin
Canvas.Brush.Color := clBackGround;
Canvas.FillRect(Rect);
ImageList1.Draw(Canvas,Rect.Left,Rect.Top,index);
if gdFocused in State then
Canvas.DrawFocusRect(Rect);
end;
end;