Bonsoir a tous ,
pour centrer une fenêtre sur un écran j'utilise cette méthode :
lors de l'appel de la procédure dans l’événement OnCreate j’obtiens une erreur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 procedure centerizeform(f:TForm); begin f.Top:=(Screen.WorkAreaHeight-f.Height) div 2; if f.Top<0 then f.Top:=0; f.Left:=(Screen.WorkAreaWidth-f.Width) div 2; if f.Left<0 then f.Left:=0; end;
j'ai vu la solution proposée sur la faq :
mais je ne sais comment et ou appelé cette procedure.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 procedure CenterWnd(const Wnd: HWND); var R: TRect; SW, SH, W, H: Integer; begin SW := GetSystemMetrics(SM_CXSCREEN); SH := GetSystemMetrics(SM_CYSCREEN); GetWindowRect(Wnd, R); W := R.Right - R.Left; H := R.Bottom - R.Top; R.Left := (SW - W) div 2; if R.Left < 0 then R.Left := 0; R.Top := (SH - H) div 2; if R.Top < 0 then R.Top := 0; MoveWindow(Wnd, R.Left, R.Top, W, H, True); end;
Partager