如何在StringGrid或DrawGrid的中单元格内插入图片?

解决方案 »

  1.   

    给你个例子看看:
    stringgrid1.Canvas.Draw(30,30,application.Icon);
      

  2.   

    In your StringGrid's OnDrawCell event handler, place some code that resembles:     with StringGrid1.Canvas do
            begin
            {...}
            Draw(Rect.Left, Rect.Top, Image1.Picture.Graphic);
            {...}
            end;Using the Draw() or StretchDraw() method of TCanvas should do the trick.  BTW, Image1 above is a TImage with a bitmap already loaded into it.
      

  3.   

    //在它们的StringGrid.OnDrawCell事件里写,下面的一个DBGrid的例子
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);var
          R : TRect;
    begin
          R := Rect;
          DBGrid1.Canvas.StretchDraw(Rect, Image1.Picture.Graphic);
          DrawText(DBGrid1.Canvas.Handle, pChar(DBGrid1.DataSource.DataSet.Fields[Column.Index].AsString), -1, R, DT_SINGLELINE or DT_CENTER);
    end;
      

  4.   

    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var
      Bitmap: TBitmap;
    begin
      bitmap := TBitmap.Create;
      Bitmap.LoadFromFile('C:\Program Files\Common Files\Borland Shared\Images\Buttons\ABORT.BMP');
      StringGrid1.Canvas.BrushCopy(Rect, Bitmap, Rect, clWhite);
    end;
      

  5.   

    Drawgrid1.Canvas.StretchDraw(Drawgrid1.CellRect(x,y),Image1.Picture.Bitmap);
    //x:填你Drawgrid1的列值
    //y:填你Drawgrid1的行值
      

  6.   

    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var
      bmpF: TBitmap;
    begin
      bmpF := TBitmap.Create;
      bmpF.LoadFromFile('d:\tmp.bmp');
      StringGrid1.Canvas.Draw(Rect.Left, Rect.Top, bmpF);
      bmpF.Free;
    end;
      

  7.   

    此贴已结,谢谢各位的参与,我要将分给lion_lh(xmanx)