...center a TControl?

Author: Jürgen Poley

Category: VCL

procedure CenterControl(ParentObject, CenterObject: TControl; bTop, bLeft: Boolean;
  Space: Integer);
begin
  with 
CenterObject do
  begin
    if 
bLeft then
      
Left := ParentObject.Width div 2 - Width div 2 + Space;

    if bTop then
      
Top := ParentObject.Height div 2 - Height div 2;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  
CenterControl(Panel1, Button1, True, True, 0);
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base