保持各組件相對窗體的位置

在BCB中,一旦組件放下,其位置也就固定了,所以當鼠標拉動窗口後,組件會保持不變,下面代碼實現各組件相對窗體位置不變功能

 

TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormResize(TObject *Sender)
{
    int ixPos = Width / 2;
    int iyPos = Height / 2;
    TControl *pControl;
    for(int i = 0; i < ControlCount; i++){
        pControl = Controls[i];
        pControl->Left = ixPos - pControl->Width / 2;
        pControl->Top = iyPos - pControl->Height / 2;
    }
}
//---------------------------------------------------------------------------

發佈了21 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章