在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;
}
}
//---------------------------------------------------------------------------