2015-09-24 80 views
1

我想在運行時將新的面板添加到我的表單中,但我遇到的問題是,將它們對齊到頂部時,它們不會按照我創建它們的順序顯示。如何在運行時在Builder XE6中動態添加組件?

我使用DisableAlign()和EnableAlign()來跟蹤這篇文章的提示。 How to dynamically create controls aligned to the top but after other aligned controls? 這適用於我添加的前四個面板。

__fastcall TForm1::TForm1(TComponent* Owner) 
    : TForm(Owner) 
{ 
    TPanel * test; 
    Panel1->DisableAlign(); 

    for(int i = 0; i<4; i++){ 
     test = new TPanel(Panel1); 
     test->Caption = i; 
     test->Parent = Panel1; 
     test->Align = alTop; 
    } 
    Panel1->EnableAlign(); 
} 

Screen 1

但後來我想補充一下按鈕時,另一面板:

void __fastcall TForm1::Button1Click(TObject *Sender) 
{ 
     Panel1->DisableAlign(); 

     TPanel * test; 
     test = new TPanel(Panel1); 
     test->Caption = 5; 
     test->Parent = Panel1; 
     test->Align = alTop; 

    Panel1->EnableAlign(); 
} 

,這出現:

Screen 2

有什麼辦法讓對齊做我想要的事情ut搞亂Top Settings或不重建整個表單?

+3

你必須設置頂部 –

回答

2

這很簡單。在設置Align之前,您必須將Top設置爲適當的值。將Top設置爲底部面板底部的座標。

相關問題