Delphi DBGrid绘图单元格图像黑色背景



使用来自Fimage列表中的图像将字形绘制到DBGRID中的数据单元的问题:

我正在将" checkmark"的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;

执行默认的单元格绘画 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;

我猜您所描述的是因为没有绘画单元背景的代码而发生的。

最新更新