delphi关于带图片显示的表,怎么做?
像这样显示的表,里面有图片。用哪种控件比较好 ,怎么显示呢?
[解决办法]
为了在DBGrid中显示图象,要设置OnDrawColumnCell事件。
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
bmp:tbitmap;
outrect:trect;
bmpwidth:integer;
begin
outrect:=rect;
if (column.Field =table1.fields.FieldByName('Common_Name')) then
begin
bmp:=tbitmap.Create;
try
bmp.Assign(table1.fieldbyname('Graphic'));
bmpwidth:=(rect.Bottom -rect.Top )*2;
outrect.Right :=rect.Left +bmpwidth;
dbgrid1.Canvas.StretchDraw(outrect,bmp);
except
bmp.free;
end;
if table1.fieldbyname('Length (cm)').asinteger>100 then
begin
dbgrid1.Canvas.Font.color:=clred;
dbgrid1.Canvas.Font.style :=[fsbold];
end;
outrect:=rect;
outrect.left:=outrect.Left +bmpwidth;
end;
//dbgrid1.defaultdrawdatacell(rect,column.field,state);
dbgrid1.DefaultDrawDataCell(outrect,column.field,state);
end;