Author: Jonas Bilinkevicius How to center a TOpenDialog on a form Answer: 1 { ... } 2 type 3 TForm1 = class(TForm) 4 Button1: TButton; 5 OpenDialog1: TOpenDialog; 6 procedure Button1Click(Sender: TObject); 7 procedure OpenDialog1Show(Sender: TObject); 8 private 9 { Private declarations } 10 procedure MoveDialog(var Msg: TMessage); message WM_USER; 11 public 12 { Public declarations } 13 end; 14 15 var 16 Form1: TForm1; 17 18 implementation 19 20 {$R *.DFM} 21 22 procedure TForm1.Button1Click(Sender: TObject); 23 begin 24 OpenDialog1.Execute; 25 end; 26 27 procedure TForm1.OpenDialog1Show(Sender: TObject); 28 begin 29 PostMessage(Self.Handle, WM_USER, 0, 0); 30 end; 31 32 procedure TForm1.MoveDialog(var Msg: TMessage); 33 var 34 rec: TRect; 35 wh: HWND; 36 l, t, r, b: Integer; 37 begin 38 if ofOldStyleDialog in OpenDialog1.Options then 39 wh := OpenDialog1.Handle 40 else 41 wh := Windows.GetParent(OpenDialog1.Handle); 42 if IsWindow(wh) then 43 if GetWindowRect(wh, rec) then 44 begin 45 l := (Width - (rec.Right - rec.Left)) div 2 + Left; 46 t := (Height - (rec.Bottom - rec.Top)) div 2 + Top; 47 r := rec.Right - rec.Left; 48 b := rec.Bottom - rec.Top; 49 MoveWindow(wh, l, t, r, b, True); 50 end; 51 end;