放一个ImageList,把位图或图标添加进去,然后在StringGrid的OnDrawCell事件中: procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var bm: TBitmap; begin with StringGrid1.Canvas do if (ACol = 1) and (ARow = 1) then begin bm := TBitmap.Create; ImageList1.GetBitmap(0, bm); StringGrid1.Canvas.Draw(Rect.Left, Rect.Top, bm); bm.Free; end; end;
来自沪上傅远山的致意([email protected]): upstairs,I can't agree with you more!
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
bm: TBitmap;
begin
with StringGrid1.Canvas do
if (ACol = 1) and (ARow = 1) then begin
bm := TBitmap.Create;
ImageList1.GetBitmap(0, bm);
StringGrid1.Canvas.Draw(Rect.Left, Rect.Top, bm);
bm.Free;
end;
end;
upstairs,I can't agree with you more!
那里有下载呀,我手里没有!
DrawCell不用你去调用的,StringGrid收到要重画的消息自己会调用DrawCell的,你只要在里面判断当前这个cell是不是你要添加图标上去的,是的话就用上面那段代码把图标添加上去。
比如我想根据不同的文件类型在STRINGGRID每一行的末尾画上一个表示该文件类型的图标,当我切换到另外一个文件夹时,画上去的图标就随着新文件夹中的文件类型而改变!!!
谢谢!!!!!!!!
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
bm: TBitmap;
begin
with StringGrid1.Canvas do
if ACol = StringGrid1.ColCount-1 then begin // 在最后一列画图标
bm := TBitmap.Create;
ImageList1.GetBitmap(ARow, bm); // ARow是当前行,也是图标在IMAGELIST里的位置
StringGrid1.Canvas.Draw(Rect.Left, Rect.Top, bm);
bm.Free;
end;
end;
只有在DRAWCELL中才能画吗??能不能写一个过程来画图标??