Reputation: 570
Using C++ Builder v. 10.2.3, I want to center a TForm that is being resized. To do this, I use the TScreen::WorkArea values. However, running on a system with Windows 10 scaling at 125%, the code doesn't work properly, as the TForm is scaled up. How can I determine if such scaling is occurring, and then adjust accordingly? Is there built in functionality in FireMonkey to do this? I should note that with scaling > 100% in Windows 10, the TForm::TPosition values don't seem to work properly - for example, setting it to ScreenCenter seems to have a similar problem, where it isn't actually centered.
Upvotes: 2
Views: 2320
Reputation: 570
The C++ equivalent of Hans' answer is
double GetScreenScale ()
{
double value = 1.0;
_di_IFMXScreenService screenService;
if (TPlatformServices::Current->SupportsPlatformService (__uuidof (IFMXScreenService), &screenService))
value = screenService->GetScreenScale ();
return value;
}
Upvotes: 2
Reputation: 2262
This function will return the screen scaling, i.e. 1.25 if you are using 125% scaling on Windows:
function GetScreenScale: Single;
var ScreenService: IFMXScreenService;
begin
Result := 1;
if TPlatformServices.Current.SupportsPlatformService (IFMXScreenService, IInterface(ScreenService)) then
Result := ScreenService.GetScreenScale;
end;
Note that on Mac, the only screen scaling possible is 1.0 (non-retina) and 2.0 (retina). However, on the Mac the values returned by TScreen are already scaled, so no correction is needed.
Upvotes: 3