怎样才能将图片加入到DrawGrid每一个网格中,在线等候.

awi 2003-08-20 02:01:12
怎样才能将图片加入到DrawGrid每一个网格中,而且图片不尽相同?
...全文
119 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
kedao 2003-08-20
  • 打赏
  • 举报
回复
在下面onDrawColumnCell事件处理程序中的代码所示:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
Bmp: TBitmap;
OutRect: TRect;
BmpWidth: Integer;
begin
// default output rectangle
OutRect := Rect;

if Column.Field = 绘制图片的列 then
begin
// draw the image
Bmp := TBitmap.Create;
try
Bmp.Assign (图片域);
BmpWidth := (Rect.Bottom - Rect.Top) * 2;
OutRect.Right := Rect.Left + BmpWidth;
DBGrid1.Canvas.StretchDraw (OutRect, Bmp);
finally
Bmp.Free;
end;
// reset output rectangle, leaving space for the graphic
OutRect := Rect;
OutRect.Left := OutRect.Left + BmpWidth;
end;



// default drawing
DBGrid1.DefaultDrawDataCell (OutRect, Column.Field, State);
end;
awi 2003-08-20
  • 打赏
  • 举报
回复
谢谢!
awen16862 2003-08-20
  • 打赏
  • 举报
回复
DrawGrid1.Canvas.StretchDraw(DrawGrid1.CellRect(i,j),Images1.Picture.Graphic );
free007 2003-08-20
  • 打赏
  • 举报
回复
Rect.Left+22,Rect.Top+5是为了调整图片的位置
free007 2003-08-20
  • 打赏
  • 举报
回复
将你需要添加的图片放到一个ImageList中然后在DrawGrid的OnDrawCell事件中如下:

procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
index: integer;
begin
index := ARow * DrawGrid1.ColCount + ACol;
with Sender as TDrawGrid do
begin
Canvas.FillRect(Rect);
ImageList1.Draw(Canvas,Rect.Left+22,Rect.Top+5,index);

end;
end;
对于StringGrid以上同样可以使用
awi 2003-08-20
  • 打赏
  • 举报
回复
是文件
OO_is_just_P 2003-08-20
  • 打赏
  • 举报
回复
是数据库重的图还是文件?
cjx 2003-08-20
  • 打赏
  • 举报
回复
关注!!!

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧