将图像插入到字符串格中 [英] inserting image in stringgrid cell

查看:155
本文介绍了将图像插入到字符串格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中使用stringgrid。数据从数据库(后端mysql)中获取并显示在stringgrid中。

i m using stringgrid in my application.The data is fetched from the database(backend mysql) and displayed in stringgrid.

我想在每行的状态单元格中插入图像。
ie

I want to insert image in status cell of each row. i.e.

      if status =online then -->image1
      else --->image2

任何人都知道如何做到这一点?

anyone has any idea regarding how to do this?

推荐答案

您将不得不实施OnDrawCell事件。

You will have to implement the OnDrawCell event.

示例:

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Longint;
  Rect: TRect; State: TGridDrawState);
var
  s: string;
  aCanvas: TCanvas;
begin
  if (ACol <> 1) or (ARow = 0) then
    Exit;
  s := (Sender as TStringGrid).Cells[ACol, ARow];

  // Draw ImageX.Picture.Bitmap in all Rows in Col 1
  aCanvas := (Sender as TStringGrid).Canvas;  // To avoid with statement
  // Clear current cell rect
  aCanvas.FillRect(Rect);
  // Draw the image in the cell
  if (s = 'online') then
    aCanvas.Draw(Rect.Left, Rect.Top, Image1.Picture.Bitmap)
  else 
    aCanvas.Draw(Rect.Left, Rect.Top, Image2.Picture.Bitmap);
end;

这篇关于将图像插入到字符串格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆