可不可实现动态放置控件(100分)

  • 主题发起人 Tigerchamp
  • 开始时间
T

Tigerchamp

Unregistered / Unconfirmed
GUEST, unregistred user!
有一个想法,希望能在程序中动态地在一个空FORM上放置一些控件,不知能否实现,请诸位大侠帮助解答。
 
你想放什么控件?
 
当然可以。在Create后,将其Parent置为Form就行。
var
But : TButton;
begin
But := TButton.Create;
But.Parent := Form1
// 或者是其他容器控件,如TPanel
end

可以看一下这里的已答问题!
 
可以,你还可以利用下面这个程序实现动态的控件矩阵.
var
i: Integer;
lblPick: array[0..14] of TButton;

begin
for i := 0 to 14 do
begin
lblPick := TLabel.Create(TForm);
lblPick.Parent := form
//注意将其Parent置为容器(一般为Form)
lblPick.Left := 192 + 32 * i;
lblPick.Top := 61 + (i mod 5) * 10;
lblPick.Caption := IntToStr(i + 1);
end;
end;
 
Var
MyButton : TButton;

MyButton := TButton.Create(MyForm)
// MyForm now "owns" MyButton
with MyButton do
BEGIN
Parent := MyForm
// here MyForm is also the parent of MyButton
height := 32;
width := 128;
caption := 'Here I Am!';
left := (MyForm.ClientWidth - width) div 2;
top := (MyForm.ClientHeight - height) div 2;
END;



Borland also publishes one of their TechInfo sheets on this
subject.

Look for

ti2938.asc Creating Dynamic Components at Runtime

which you can get from Borland's web site or ftp site.
 
多人接受答案了。
 

Similar threads

顶部