我把2个image图像 画到一个AdvStringGrid的所有行的单元格里。(除了第一行)。
然后想实现通过点击不同的图片实现不同的功能(比如说弹出行号列号图片名称等)。这个我是通过判断鼠标的位置是否在这个图片的矩形框里,通过TRect来设定矩形的坐标的,但是出现问题了。详细看代码
for I := 1 to AdvStringGrid1.RowCount - 1 do
begin
      ARect:=AdvStringGrid1.CellRect(1,i);//这是添加图像,这个可以画进去。
      iX :=  ARect.Left +10;
      iY := ARect.Top+30;
      AdvStringGrid1.Canvas.Brush.Style := bsClear;
      AdvStringGrid1.Canvas.Draw(iX, iy, Image1.Picture.Graphic);
      AdvStringGrid1.Canvas.Draw(iX + Image1.Width , iy, Image2.Picture.Graphic);
end;procedure TForm1.AdvStringGrid1ClickCell(Sender: TObject; ARow, ACol: Integer);
var
  IsInImg: Boolean;
  ARect,ARect1,ARect2: TRect;
  APt: TPoint;
  Str: String;
begin
  with AdvStringGrid1 do
  //if(ACol = 1) then
//  begin
    ARect := CellRect(ARow,ACol);
    ARect1.Left :=ARect.Left+10;
    ARect1.Right := ARect1.Left + Image1.Width;
    ARect1.Top := ARect.top + 30;
    ARect1.Bottom := ARect1.Top + Image1.Height;
    edit1.Text:='上'+inttostr(ARect.Top);//由于对TRect的坐标不了解,特意把值写到edit里,可这个top好像不是顶部的距离
    edit2.Text:='左'+inttostr(ARect.Left);//这个left也是一个道理
    edit3.Text:='右'+inttostr(ARect.Right);
    edit4.Text:='下'+inttostr(ARect.Bottom);    APt := ScreenToClient(Mouse.CursorPos);
    if Windows.PtInRect(ARect1,APt) then
    begin
      ShowMessage('发送短信');
      Button1Click(sender);
    end;    ARect2 := ARect1;
    ARect2.Left := ARect1.Right + 10;
    ARect2.Right := ARect2.Left + Image2.Width;
    if Windows.PtInRect(ARect2,APt) then
    begin
      ShowMessage('立即通话');
      Button1Click(sender);
    end;
 Button1Click(sender);
end;