domingo, 24 de maio de 2009

Centralizando um form no desktop (via código)

Var
r : TRect;
osv : TOSVersionInfo;
begin
osv.EdwOSVersionInfoSize := sizeof(osv);
GetVersionEx(osv);
if osv.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS then
begin
SystemParametersInfo(SPI_GETWORKAREA, 0, @r, 0);
Left := ((r.right - r.left) - Width) div 2;
Top := ((r.bottom - r.top) - Height) div 2;
end
else
begin
Left := (GetSystemMetrics(SM_CXSCREEN) - Width) div 2;
Top := (GetSystemMetrics(SM_CYSCREEN) - Height) div 2;
end;
end;
{Ou simplesmente vá até a propriedade Position do form e selecione poScreenCenter. }

Nenhum comentário:

Postar um comentário