简体   繁体   English

德尔福dbgrid绘图单元格图像黑色背景

[英]delphi dbgrid drawing cell image black background

Problem using image from a TImage list to draw a glyph on to a data cell in DBGrid: 使用TImage列表中的图像在DBGrid的数据单元上绘制字形时出现问题:

I am putting a bmp image of a "checkmark" in place of the text "Done" in a particular data cell. 我在特定数据单元格中将“选中标记”的bmp图像替换为文本“完成”。 It works, but there is always black color in the parts of the cell not covered by the image. 它可以工作,但是在单元格中未被图像覆盖的部分始终存在黑色。 I have tried enlarging the pixel size of the bmp image to match the cell size, but it always seems to resize the image for me. 我曾尝试放大bmp图像的像素大小以匹配单元格大小,但它似乎总是为我调整图像大小。 Using Delphi 10.2, was not problem in D7? 使用Delphi 10.2,在D7中不是问题吗?

Have tried many combos of setting background colors, pen and brush colors, etc. Here is a simple example of one code attempt: 尝试了许多设置背景色,笔和笔刷颜色等的组合。这是一个代码尝试的简单示例:

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;

Do the default cell painting DefaultDrawColumnCell always. 始终执行默认的单元格绘画DefaultDrawColumnCell That will ensure the cell will look like the others. 这样可以确保该单元格看起来像其他单元格。 Then draw the image. 然后绘制图像。 Try this: 尝试这个:

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;

I guess that what you described happens because there is no code that paints the cell background. 我想您所描述的是发生的,因为没有代码可以绘制单元格背景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM