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.
//在它们的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;
stringgrid1.Canvas.Draw(30,30,application.Icon);
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.
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;
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;
//x:填你Drawgrid1的列值
//y:填你Drawgrid1的行值
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;