2017-05-31 22 views
1

问题上绘制在DBGrid的数据单元的字形:德尔福DBGRID绘制细胞图像的黑色背景使用图像从一个的TImage列表

我来代替文字把一个“对号”一个BMP图像“完成“在一个特定的数据单元中。它可以工作,但在图像未覆盖的单元部分总是有黑色。我曾尝试扩大bmp图像的像素大小以匹配单元大小,但似乎总是为我调整图像大小。使用Delphi 10.2,在D7中不是问题?

试过设置背景颜色,画笔和画刷颜色等许多连击这里是一个代码尝试一个简单的例子:

procedure TFUpRepWS.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; 
    DataCol: Integer; Column: TColumn; State: TGridDrawState); 
begin 
    with Column do begin 
    if ((FieldName = 'Done') and (Field.AsString = 'x')) then begin 
    //below shows black outside of check mark image in the cell 
     ImageList1.Draw(DBGrid1.Canvas,Rect.Left,Rect.Top,0) 
    end 
    else DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State); 
    end; 
end; 

回答

2

执行默认的单元格画DefaultDrawColumnCell始终。这将确保细胞看起来像其他人。然后绘制图像。试试这个:

procedure TFUpRepWS.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; 
    DataCol: Integer; Column: TColumn; State: TGridDrawState); 
begin 
    with Column do 
    begin 
    DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); 
    if ((FieldName = 'Done') and (Field.AsString = 'x')) then 
     ImageList1.Draw(DBGrid1.Canvas, Rect.Left, Rect.Top, 0); 
    end; 
end; 

我猜你描述发生了什么,因为没有代码绘制单元格的背景。