捐赠 | 广告 | 注册 | 发布 | 上传 | 关于我们    
  沪ICP备05001939号 DELPHI盒子 | 盒子论坛 | 盒子文章 | 盒子问答悬赏 | 最新更新 | 论坛检索 | 下载中心 | 高级搜索    
  精品专区 | 繁體中文 | 奖励公告栏 | 直通车账号登陆 | 关闭GOOGLE广告 | 临时留言    
盒子资源分类
全部展开 - 全部合拢
从路径载入图片的数据控件dbpathimage(无下载)
关键字:dbpathimage
来 自:原创
平 台:Win2003 下载所需:0 火柴
深浅度:初级 完成时间:2010/4/21
发布者:cd_fsy2000 发布时间:2010/4/29
编辑器:DELPHI5 语  种:简体中文
分 类:数据库 下载浏览:2074/10576
加入到我的收藏
下载错误报错
登陆以后才能下载
 用户名:
 密 码:
自动登陆(30天有效)
图片如果打不开,说明流量不够了,请稍候下载……
小弟刚刚写了个可以从路径载入图片的数据控件dbpathimage,第一次写整了半天,不敢藏私,特来分享给大家,由于是第一次写,不足之处还请大家多多指正,很简单所以直接把代码贴上来了,大家拷贝下去直接建个unit安装一下就ok了,代码如下:
unit dbpathimage;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  DBCtrls,db;

type
  Tdbpathimage = class(TDBImage)
   private
    fTransparent: boolean;
   protected
    procedure Paint; override;
    procedure SetTransparent(const Value: boolean);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Transparent: boolean read fTransparent write SetTransparent default True;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Data Controls', [Tdbpathimage]);
end;


constructor Tdbpathimage.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  //使用双缓冲绘制图片,先把图片绘制到内存中,
  //然后在显示到控件中,这样就不会闪烁
  self.DoubleBuffered:=true;
end;

destructor Tdbpathimage.Destroy;
begin
  inherited Destroy;
end;

procedure TDBpathImage.SetTransparent(const Value: boolean);
begin
  fTransparent := Value;
  Invalidate;
end;


procedure Tdbpathimage.Paint;
var
  Size: TSize;
  R: TRect;
  S: string;
  DrawPict: TPicture;
  Form: TCustomForm;
  Pal: HPalette;
begin
  with Canvas do
  begin
      Brush.Style := bsSolid;
      Brush.Color := Color;
      DrawPict := TPicture.Create;
      Pal := 0;
      s:='';
      try
          if (field=nil) or (field.asstring='') then
          begin
          Font := Self.Font;
          S := '(无图片)';
          Size := TextExtent(S);
          R := ClientRect;
          TextRect(R, (R.Right - Size.cx) div 2, (R.Bottom - Size.cy) div 2, S);
          end
          else
          begin
          try  //当调入图片失败后,显示'调入失败'
          DrawPict.LoadFromFile(field.asstring);
          if DrawPict.Graphic is TBitmap then
          DrawPict.Bitmap.IgnorePalette := QuickDraw;
          except
          Font := Self.Font;
          S := '(调入失败)';
          Size := TextExtent(S);
          R := ClientRect;
          TextRect(R, (R.Right - Size.cx) div 2, (R.Bottom - Size.cy) div 2, S);
          end;
          end;
          if Stretch then
          begin
          if (DrawPict.Graphic = nil) or DrawPict.Graphic.Empty then
          begin
          Font := Self.Font;
          if s='' then S := '(无图片)';
          Size := TextExtent(S);
          R := ClientRect;
          TextRect(R, (R.Right - Size.cx) div 2, (R.Bottom - Size.cy) div 2, S);
          end
          //FillRect(ClientRect)
          else
          StretchDraw(ClientRect, DrawPict.Graphic);
          end
          else
          begin
          SetRect(R, 0, 0, DrawPict.Width, DrawPict.Height);
          if Center then OffsetRect(R, (ClientWidth - DrawPict.Width) div 2,
          (ClientHeight - DrawPict.Height) div 2);
          StretchDraw(R, DrawPict.Graphic);
          ExcludeClipRect(Handle, R.Left, R.Top, R.Right, R.Bottom);
          FillRect(ClientRect);
          SelectClipRgn(Handle, 0);
          end;
      finally
          if Pal <> 0 then SelectPalette(Handle, Pal, True);
          DrawPict.Free;
      end;
    end;
end;

end.
Google
 
本站原创作品,未经作者许可,严禁任何方式转载;转载作品,如果侵犯了您的权益,请联系我们
龙脉加密锁 15元起 Grid++Report 报表 申请支付@网
 相关文章
没有相关文章
相关评论
共有评论6条 当前显示最后5条评论
ozhy1 2010/4/29 11:31:09
除了BMP格式的图片
不能载入其他格式的图片
star5 2010/4/30 22:48:14
如果你要载入jpg的,引用下jpeg单元就行。

建议加个autosize,然后配合scrollbox使用,效果不错的。
ozhy1 2010/5/4 14:11:29
可以了
bgh123 2010/5/27 11:07:59
怎么样安装,请详细出一下好吗,我刚学习,时间还不常,谢了
mzfeitian 2010/7/7 15:48:30
不知有什么作用?
我要发表评论 查看全部评论
 
  DELPHI盒子版权所有 1999-2023 V4.01 粤ICP备10103342号-1 更新RSS列表