我是想根据数据的不同显示不同的图片
解决方案 »
- 求个打开文件夹并选中指定的文件
- delphi中的抽象类的定义
- 100分求,TWebBrowser中如何屏蔽javascript?
- 抢分题呀,如何使窗体放在屏幕中间?
- 我发布了一款软件,是直接将IDE里的文字处理成RTF或HTML格式,欢迎大家下载使用~~
- 我是新来得!!!问一下名字旁边的三角和星星是靠什么升的?怎么升的?
- 想做一个类似TDBLookupComboBox的组件???
- 高分求助数据导出的问题,急,急,急
- 中国delphi程序员知多少?
- 当Tedit的Enabled为false时,如何将它的颜色设为clBtnFace
- 单击form2中的一个按钮,显示form1窗体的代码怎么写?
- 高分挑战绝顶高手,如何实现象QQ上的远程协助功能?
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;
也可以在这行下面加些判断条件,根据条件加载不同的图片就行了.
这句是干什么用的?还请明示
再给个例子
Drawing an image in a cell of a Delphi DBGrid
http://delphi.about.com/library/weekly/aa032205a.htm
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
var
Index: Integer;
begin
if DataCol = 0 then
begin
DBGrid1.Canvas.FillRect(Rect); // 先清除编辑单元原有的东西
if Column.Field.AsBoolean then Index := 9 else Index := 8;
// 我的图片放在另外一个窗口的TImageList中,画就行了
MainForm.BtnImages.Draw(DBGrid1.Canvas, Rect.Left + 2, Rect.Top + 1, Index);
end;
end;