Delphi StringGrid与背景中的图片 [英] Delphi StringGrid with picture in background

查看:693
本文介绍了Delphi StringGrid与背景中的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您有没有人知道是否可以将图片显示为字符串网格的背景,或者任何人都知道可以执行此操作的任何免费网格组件。

Hi does anyone know if it is possible to display a picture as a background to a string grid, Or is anyone aware of any free Grid component that can do this.

谢谢

colin

推荐答案

您可以使用 TDrawGrid (或 TStringGrid ),它支持所有者绘图,并执行

You could use a TDrawGrid (or a TStringGrid), which supports owner-drawing, and do

procedure TForm1.FormCreate(Sender: TObject);
begin
  FBg := TBitmap.Create;
  FBg.LoadFromFile('C:\Users\Andreas Rejbrand\Pictures\Sample.bmp');
end;

其中 FBg 是一个 TBitmap (例如在表单类中),然后执行

where FBg is a TBitmap (in the form class, for instance), and then do

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  r: TRect;
begin
  if not (Sender is TStringGrid) then Exit;
  BitBlt(TStringGrid(Sender).Canvas.Handle,
         Rect.Left,
         Rect.Top,
         Rect.Right - Rect.Left,
         Rect.Bottom - Rect.Top,
         FBg.Canvas.Handle,
         Rect.Left,
         Rect.Top,
         SRCCOPY);
  if gdSelected in State then
    InvertRect(TStringGrid(Sender).Canvas.Handle, Rect);
  r := Rect;
  TStringGrid(Sender).Canvas.Brush.Style := bsClear;
  DrawText(TStringGrid(Sender).Canvas.Handle,
           TStringGrid(Sender).Cells[ACol, ARow],
           length(TStringGrid(Sender).Cells[ACol, ARow]),
           r,
           DT_SINGLELINE or DT_VCENTER or DT_END_ELLIPSIS);
end;

示例截图http://privat.rejbrand.se/drawgridbg.png
示例截图http:// privat。 rejbrand.se/drawgrid2.png
示例截图http://privat.rejbrand.se/drawgrid3.png

这篇关于Delphi StringGrid与背景中的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆