开发一个 image&label 组合控件的问题,(100)

  • 主题发起人 主题发起人 jhddx
  • 开始时间 开始时间
J

jhddx

Unregistered / Unconfirmed
GUEST, unregistred user!
我想开发一个image和一个label组合在一起的控件,因为我想他们两处在同一个基板上,以基板为父级容器,所以继承了TWinControl,主要代码如下:Type Panelview = class(TWinControl); pravite Fimage: Timage; Flabel: Tlabel; Fpicture: Tpictuer; Fcaption: Tcaption; procedure FSetpicture(Const value: Tpicture); ...Publishedproperty picture: Tpicture read Fpicture write FSetpicture;property caption: Tcaption read Fcaption write FSetcaption; Constructor TPanelview.Create(AOWner: TComponent);begin inherited; width := 265; height := 160; Fpicture := Tpicture.Create; Fimage := Timage.Create(self); Fimage.Parent := Self; Fimage.Top := 5; Fimage.Left := 5; Fimage.Width := 150; Fimage.Height := 150; Flabel:= Tlabel.create(self); Flabel.parent := Self; Flabel.Top := 5; Flabel.Left := 160; Flabel.Width := 100; Flabel.Height := 30; Flabel.Caption := '标题区域';end;procedure TPanelview.FSetpicture(Const value: Tpicture);begin Fimage.Picture.Assign(value);end;procedure TPanelview.FSetcaption(value: Tcaption);begin Flabel.Caption := value;end;end.以上控件安装后,label显示正常,image在设计时能显示,运行时就看不到了,请问下知道的朋友,这是什么问题,应该如何解决! 如果有能解决,可加分答谢!
 
你试试把图片格式换下
 
TO:79023864试过JPG和BMP格式图片,都是一样的,现在控件里的picture能接受传给他的图片,也能把里面的图片保存为文件下来,就是没有显示,好像没有绘制这个过程。
 
……我这边不会啊,坐等高人了
 
property picture: Tpicture read Fpicture write FSetpictureprocedure TPanelview.FSetpicture(Const value: Tpicture);begin Fimage.Picture.Assign(value);end;read的时候是FpictureSet的时候是Fimage.Picture而你的Fpicture跟Fimage貌似没有关系
 
TO:zhengrong117这里有点糊涂,请问可以怎么改呢?
 
create 的时候加上Fimage.Picture.Assign(Fpicture);procedure TPanelview.FSetpicture(Const value: Tpicture);begin //Fimage.Picture.Assign(value);Fpicture:=value;end;//这样改下试试
 
试了,还是不显示图片,设计时可以看到图片,运行就没了。以为是宽和高为0,运行时指定了宽高还是看不到。
 
unit ULabImg;interfaceuses Windows, Messages, StdCtrls,SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls; type TPanelview = class(TWinControl) private Fimage: Timage; Flabel:Tlabel; //Fpicture: Tpicture; Fcaption: Tcaption; //private { Private declarations } procedure FSetpicture(Const value: Timage); public Constructor Create(AOWner: TComponent); property picture: Timage read Fimage write FSetpicture; end;implementation{ TPanelview }Constructor TPanelview.Create(AOWner: TComponent);begin inherited; width := 265; height := 160; //Fpicture := Tpicture.Create; Fimage := Timage.Create(self); Fimage.Parent := Self; Fimage.Top := 5; Fimage.Left := 5; Fimage.Width := 150; Fimage.Height := 150; //Fimage.Picture.Assign(Fpicture); Fimage.Visible:=True; Fimage.Picture.LoadFromFile('C:/1232085272_ddvip_4240.bmp'); Flabel:= Tlabel.create(self); Flabel.parent := Self; Flabel.Top := 5; Flabel.Left := 160; Flabel.Width := 100; Flabel.Height := 30; Flabel.Caption := '标题区域';end;procedure TPanelview.FSetpicture(const value: Timage);beginFimage.Picture.Assign(value);// Fpicture.Assign(value);end;end.unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls,ULabImg;type TForm1 = class(TForm) img1: TImage; lbl1: TLabel; btn1: TButton; btn2: TButton; procedure FormCreate(Sender: TObject); procedure btn1Click(Sender: TObject); private Panelview:TPanelview; { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);beginPanelview.picture.Picture:=img1.Picture;end;procedure TForm1.FormCreate(Sender: TObject);beginPanelview:=TPanelview.Create(self);Panelview.Parent:=Self;img1.Picture.LoadFromFile('D:/Backup/我的文档/My Pictures/947c23d02fed0e149a5027e8.bmp');end;end.
 
吃饭回来,先研究下你的代码。
 
谢谢zhengrong117的耐心解答。谢谢79023864热心关注。
 
后退
顶部