您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> Delphi >> AdvStringGrid单元格如何添加图片,并且点击图片触发一个事件?

AdvStringGrid单元格如何添加图片,并且点击图片触发一个事件?

来源:网络整理     时间:2016/8/9 12:23:54     关键词:

关于网友提出的“ AdvStringGrid单元格如何添加图片,并且点击图片触发一个事件?”问题疑问,本网通过在网上对“ AdvStringGrid单元格如何添加图片,并且点击图片触发一个事件?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: AdvStringGrid单元格如何添加图片,并且点击图片触发一个事件?
描述:

AdvStringGrid单元格如何添加图片,并且点击图片触发一个事件?
不是单元格背景添加图片,而是在单元格里面加一行字,然后换行加一个图片,然后点击这个图片触发一个事件。
请问这个功能这样能实现吗?
如果不能实现,把图片换成字,也就是第一行是XXXXX字,第二行是XXXX字并有下划线,然后点击第二行的字,触发一个事件。这样能否实现呢?
分不是很多,全部送上。

AdvStringGrid.Cells[2,3] := 'Here we have the '#13'';//这个图片是ImageList里面的

解决方案1:

stringgrid的。。。

procedure TSMTXB_F.strg1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  bitmap:TBitmap;
begin
  WITH Sender AS TStringGrid,Canvas DO
  begin
    SetTextAlign(Handle,TA_LEFT);
    if ElasticForm1.fResize>0 then
      Font.Size:=round(24*ElasticForm1.fResize)
    else
      Font.Size:=24;
    if (ARow=1)or(ARow=2) then
      Font.Color:=clBlue;
    if (ARow=1)and(Cells[ACol,1]<>'') then
    begin
      qry_temp.Close;
      //重点工单:qry_temp.SQL.Text:='select qty from WKO_ORDER_WO where (WO_Old='+QuotedStr(LeftStr(Cells[ACol,1],6))+' or WO_New='+QuotedStr(LeftStr(Cells[ACol,1],6))+') and IsZD=1';
      qry_temp.SQL.Text:='select top 1 WKO_TYPE from WKO_ORDER where WKO_ORDERNO='+ QuotedStr(LeftStr(Cells[ACol,1],6));
      qry_temp.Open;
      if qry_temp.FieldByName('WKO_TYPE').AsString='WT' then
        Font.Color:=clRed;
      qry_temp.Close;
    end;
    if (ARow=2)or(ARow=3) then
    begin
      if ElasticForm1.fResize>0 then
        Font.Size:=Round(24*ElasticForm1.fResize)
      else
        Font.Size:=24;
    end;
    if (ARow=5) then
    begin
      if ElasticForm1.fResize>0 then
        Font.Size:=round(24*ElasticForm1.fResize)
      else
        Font.Size:=24;
      Font.Color:=clGreen;
      if YCC[ACol]='' then
        YCC[ACol]:=Cells[acol,arow] else
      begin
        if YCC[ACol]<>Cells[acol,arow] then
          Brush.Color:=RGB(249,140,149);
        YCC[ACol]:=Cells[acol,arow];
      end;
    end;
    if (ARow=6)and(Cells[ACol,ARow]<>'') then
    begin
      if Cells[ACol,ARow]='0' then
        Brush.Color:=RGB(121,253,154)
      else if StrToInt(Cells[ACol,ARow])<0 then
        Font.Color:=clRed;
    end;
    if (ARow=9)and(Cells[ACol,ARow]<>'') then
    begin
      if IsProgress then
      begin
        if StrToFloat(Copy(Cells[acol,arow],0,Pos('%',Cells[acol,arow])-1))=100.0 then
          Font.Color:=clGreen;
      end else
      begin
        if (StrToFloat(Copy(Cells[acol,arow],0,Pos('%',Cells[acol,arow])-1))<90.0)or(StrToFloat(Copy(Cells[acol,arow],0,Pos('%',Cells[acol,arow])-1))>180.0) then
          Font.Color:=clRed;
      end;
    end;
    FillRect(Rect);
    //if ARow=5 then
    TextRect(Rect,Rect.Left+4,Rect.Top+round(RowHeights[ARow]/2)-17,Cells[aCol,aRow]);
    //else
      //TextRect(Rect,Rect.Left+round(ColWidths[ACol]/2)-2,Rect.Top+round(RowHeights[ARow]/2)-15,Cells[aCol,aRow]);
    if ARow=5 then
    begin
      if Cells[ACol,2]<>'' then
      begin
        qry_temp.Close;
        qry_temp.SQL.Text:='select Qpa from RES_QPA where Lh='+ QuotedStr(Cells[ACol,2]);
        qry_temp.Open;
        if qry_temp.RecordCount=1 then
        begin
          bitmap:=TBitmap.Create;
          case qry_temp.FieldByName('Qpa').AsInteger of
            2:bitmap.Assign(img2.Picture);
            3:bitmap.Assign(img3.Picture);
            5:bitmap.Assign(img5.Picture);
            10:bitmap.Assign(img10.Picture);
            20:bitmap.Assign(img20.Picture);
            50:bitmap.Assign(img50.Picture);
            80:bitmap.Assign(img80.Picture);
            100:bitmap.Assign(img100.Picture);
          end;
          try
            Draw(Rect.Right-16,Rect.Top,bitmap);
          finally
            bitmap.Free;
          end;
        end;
      end;
    end;  
  end;
end;
解决方案2:

把图标画上去(stringgrid也可以把图标画进单元格内),至於事件你得研究一下(比如说用hook到图片元素再触发事件)。。。

procedure TForm1.AdvStringGrid1DrawCell(Sender: TObject; ACol,
 ARow: Integer; Rect: TRect; State: TGridDrawState);
var
 d: TBitmap;
Const
 Path= 'C:\01.bmp';
begin
 d:= TBitmap.Create;
 //d.LoadFromStream(imagelist2);
 d.LoadFromFile(Path);
 if (ACol = 2) and (ARow = 2)  then
 begin
   AdvStringGrid1.Canvas.Draw(Rect.Left,Rect.Top,d);
   AdvStringGrid1.Canvas.Draw(Rect.right-16,Rect.Top,d);
   AdvStringGrid1.Canvas.Draw(Rect.left,Rect.top+16,d);
   AdvStringGrid1.Canvas.Draw(Rect.right-16,Rect.top+16,d);
//    AdvStringGrid1.Canvas.Draw(Rect.left,Rect.bottom,d);
//    AdvStringGrid1.Canvas.Draw(Rect.right-16,Rect.bottom,d);
 end;
 d.Free;
end; 

以上介绍了“ AdvStringGrid单元格如何添加图片,并且点击图片触发一个事件?”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3154894.html

相关图片

相关文章