本文介绍了如何将Delphi中所有带有TPanel的TLabel复制到另一个TPanel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个德尔福形式的TPanel,我想复制所有的TLabel父母与这个TPanel当我按一个按钮,并把他们
在其他面板。
有没有办法呢?
谢谢。
解决方案
到复制
TLabel控件从一个TPanel到另一个你可以使用这样的东西
过程CopyLabels(ParentControl,DestControl:TWinControl);
var
i:integer;
ALabel:TLabel;
开始
为i:= 0到ParentControl.ControlCount - 1 do
如果ParentControl.Controls [i]是TLabel然后
begin
ALabel:= TLabel.Create (DestControl);
ALabel.Parent:= DestControl;
ALabel.Left:= ParentControl.Controls [i] .Left;
ALabel.Top:= ParentControl.Controls [i] .Top;
ALabel.Width:= ParentControl.Controls [i] .Width;
ALabel.Height:= ParentControl.Controls [i] .Height;
ALabel.Caption:= TLabel(ParentControl.Controls [i])。
//您可以手动添加更多的属性,如字体或另一个
end;
结束
并使用这样
CopyLabels(Panel1,Panel2);
您也可以使用 RTTI
将属性从控件复制到另一个控件,但由于您没有指定Delphi版本,我只显示一个简单的例子。
I have a TPanel on a delphi form, I want to copy all the TLabels parented with this TPanel when i press a button and put themin other panel.Is there a way to do that?Thanks.
解决方案
To copy
the TLabel controls from one TPanel to another you can use something like this
Procedure CopyLabels(ParentControl,DestControl:TWinControl);
var
i : integer;
ALabel : TLabel;
begin
for i := 0 to ParentControl.ControlCount - 1 do
if ParentControl.Controls[i] is TLabel then
begin
ALabel:=TLabel.Create(DestControl);
ALabel.Parent :=DestControl;
ALabel.Left :=ParentControl.Controls[i].Left;
ALabel.Top :=ParentControl.Controls[i].Top;
ALabel.Width :=ParentControl.Controls[i].Width;
ALabel.Height :=ParentControl.Controls[i].Height;
ALabel.Caption:=TLabel(ParentControl.Controls[i]).Caption;
//you can add manually more properties here like font or another
end;
end;
and use like this
CopyLabels(Panel1,Panel2);
you can use the RTTI
too, to copy the properties from a control to another, but as you does not specify your Delphi version only i show a simple example.
这篇关于如何将Delphi中所有带有TPanel的TLabel复制到另一个TPanel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!