大家好.我在写程序时遇到这样一个问题:
在一个Panel中放了Image控件.Image控件将根据性别贴上不同的图片.Panel的Name,Caption属性也将在程序运行时根据条件而改变.
请问:
如何在程序运行时根据指定数目 复制/生成 上述 Panel ?
谢谢!
在一个Panel中放了Image控件.Image控件将根据性别贴上不同的图片.Panel的Name,Caption属性也将在程序运行时根据条件而改变.
请问:
如何在程序运行时根据指定数目 复制/生成 上述 Panel ?
谢谢!
解决方案 »
- delphi XE 有什么新特点?
- dll中使用TreeView出現問題,請求解決
- ActiveX控件数字签名的问题!!!
- 请问RadioGroup里的ITEM怎么分成两列?
- 高手,请你帮我看一下,行么?先谢了
- 如何在asp的后台组件中访问数据库
- 小弟对delphi的B/S结构编程很有兴趣可惜对此一窍不通,期望哪位高人能够给个相关的例子给参考参考!谢谢!
- 我做了一个小软件,怎么样设置可以使得有的模块启动慢时,鼠标变为砂漏??
- chechy,老鱼,老千,小新,老龟,x空间,凡是认识 牛虻 的,请来留个qq,方便联系,多谢//牛虻
- 关于三层结构的问题!
- 问个SQL语句问题
- 谁能帮我看看这段代码 就是看看他是怎样循环的 谢谢啦 菜鸟帮帮我啊
Image: TImage;
begin
for i:=1 to n do
begin
Image:=TImage.Create(Self);
Image.Parent:=Form1;
Image.Name:='button'+inttostr(i);
Image.Left:=40*i;
Image.Top:=20;
Image.Text:='button'+inttostr(i);
Image.width:=50;
end;end;
然后取得已经存在的Panel的属性,对新建的Panel进行赋值
begin
i:=self.adoquery1.recno;
xb:=self.adoquery1.fieldbyname('xb);//性别
name:=self.adoquery1.fieldbyname('name');//姓名
pa:=Tpanel.create(form1);
pa.parent:=form1;
pa.align:=altop;
pa.name:='panel'+inttostr(i);
pa.caption:=name; im:=Timage.create(form1);
im.parent:=pa;
im.name:='image'+inttostr(i);
im.autosize:=true;
if xb='男' then
im.picture.bitbmp.loadformfile('c:\image\man.bmp')
else
im.picture.bitbmp.loadformfile('c:\image\man.bmp')//路径自己处理 ,这里写成了绝对路径
im.left:=(pa.width-im.width) div 2;
im.top:=(pa.height-im.height) div 2;
end;上面panle和image的位置,自己根据实际需要修改就可以了
1. 怎么复制这个Panel?
2. 怎么删除这个Panel?
谢谢!
2、panelold.free
1)首先创建一个panel,新创建这个panel,除了name其它属性全部用原panel属性赋值
2)遍历原panel上所有控件,并在新panel上逐个创建,同样,除了name外其它全部用原控件属性赋值大体代码如下:(设原panel的name为panel1) pa:=Tpanel.create(form1);
pa.parent:=form1;
pa.align:=panel1.align;
pa.name:='panell'+inttostr(i);//这个i应该是全局变量,根据复制次数自动更新其值
pa.caption:=panel1.caption;
pa.left:=panel1.left;
pa.top:=panel1.top; m:=self.panel1.ControlCount;
if m>0 then
begin
for n:=0 to m-1 do
begin
if self.panel1.Controls[n].ClassName<>'TImage' then
begin
im:=Timage.create(form1);
im.parent:=pa;
im.name:='imagee'+inttostr(i);
im.autosize:=(self.panel1.Controls[n] as TImage).autosize;
im.left:=(self.panel1.Controls[n] as TImage).left;
im.top:=(self.panel1.Controls[n] as TImage).top;
im.width:=(self.panel1.Controls[n] as TImage).width;
im.height:=(self.panel1.Controls[n] as TImage).height;
im.picture.bitbmp:=(self.panel1.Controls[n] as TImage).picture.bitbmp;
end;
end;
end;
2.panel1.free;
procedure TfrmWSview.CreateSickbed(BQID: string);
var
CWSQL, CWID: string;
lTop, lLeft: Integer;
btnX: TRzBitBtn;
begin
CWSQL:='select ID from BaseCW where BQID=:BQID order by ID';
QCX.Close;
QCX.SQL.Clear;
QCX.SQL.Add(CWSQL);
QCX.ParamByName('BQID').Value:=BQID;
QCX.Open;
while not QCX.Eof do
begin
for lTop:=0 to (pnBed.Height div 65) do
for lLeft:=0 to (pnBed.Width div 57) do
begin
if QCX.Eof then Exit; CWID:=QCX.FieldByName('ID').AsString;
btnX:=TRzBitBtn.Create(Self);
btnX.Parent:=pnBed;
btnX.Layout:=blGlyphTop;
btnX.Width:=57;
btnX.Height:=65;
btnX.HotTrack:=True;
btnX.Top:=lTop*65;
btnX.Left:=lLeft*57;
btnX.Name:='btn'+CWID;
btnX.Show; QCX.Next;
end;
end;
end;
2.删除代码:
procedure TfrmWSview.DestroySickbed;
var
i: Integer;
begin
for i:=0 to pnBed.ControlCount-1 do
if (pnBed.Controls[i] is TRzBitBtn) then
begin
TRzBitBtn(pnBed.Controls[i]).Free;
end;
end;当生成40个TRzBitBtn后,执行删除代码时,提示'List index out of bounds(20)',出现的情况是只能隔一个删除一个TRzBitBtn.困扰中...
之所以要删除这个生成的TRzBitBtn,是因为当我再次给BQID赋值后,生成TRzBitBtn时会提示相同名称的TRzBitBtn已经存在.