这段程序可回答您一半的问题,可不可以给一半的分?
(1)使用TStringGrid的OnDrawCell事件
(2)代码:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;Rect: TRect; State: TGridDrawState);
var
index: integer;
begin
//确定从ImageList中的图像索引号
index := ARow * (Sender as TStringGrid).ColCount + ACol;
with Sender as TStringGrid do
begin
//填充背景
Canvas.Brush.Color := clBackGround;
Canvas.FillRect(Rect);
//把imageList的图像显示在StringGrid中
ImageList1.Draw(Canvas,Rect.Left,Rect.Top,index);
if gdFocused in State then
Canvas.DrawFocusRect(Rect);
end;