下面的程序可以在StringGrid中显示ImageList中的图形(Bmp & ico)
使用TStringGrid的OnDrawCell事件
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;