Delphi でFormを MainForm 以外の中央に表示

Delphi でFormを MainForm 以外の中央に表示
親になるフォーム位置、サイズを GetWindowRect で取得して中央を計算する
  1. procedure MoveFormCenter(AForm, AParentForm: TForm);  
  2. var  
  3.     Rect: TRect;  
  4. begin  
  5.     GetWindowRect(AParentForm.Handle, Rect);  
  6.   
  7.     AForm.Top := Rect.Top + (Rect.Bottom - Rect.Top - AForm.Height) div 2;  
  8.     AForm.Left := Rect.Left + (Rect.Right - Rect.Left - AForm.Width) div 2;  
  9. end;  
(MessageDlg をフォームの中央に表示はこちら)

コメント