Frage

I am creating an application which contains custom controls (such as the TMS TAdvSmoothLabel). The problem is when the application is run on a PC with font settings set to 125% (120 DPI), it seems all components' fonts scale with the form except these custom controls. I assume the problem (as it seems to me) is that the Font property of these controls is not directly in the control. For example, a TLabel has Label.Font, while the TAdvSmoothLabel has Label.Caption.Font which controls the font size.

For a label in Segoe UI with size of 12 and height of -16, it scales to a size of 13 and height of -22. Is there a way to manually do this for fonts of various sizes? or is there a function to call to scale a font?

I also do not want to disable scaling on the forms.

War es hilfreich?

Lösung

I need to post this in an answer because of the limited comment length. To handle the scaling you need to override the ChangeScale like this:

procedure ChangeScale(M, D: Integer); override;


procedure TMyControl.ChangeScale(M, D: Integer);
begin
  inherited;
  // Now update the internal items that need to be scaled
  Label.Caption.Font.Height := MulDiv(Label.Caption.Font.Height, M, D);
  // Other items go here
end;

The component should be doing this for internal items. You could either modify the source code to scale what should be scaled or create your own control that inherits from it and do it there.

Their component should be doing something like this already if there are some changes which would mean that you will more than likely have to change their code. The alternative in that case is to do something like this which is messy:

procedure TMyControl.ChangeScale(M, D: Integer);
var
  OldHeight: Integer;
begin
  OldHeight := Label.Caption.Font.Height;
  inherited;
  // Overwrite the bad scaling in the component
  Label.Caption.Font.Height := MulDiv(OldHeight, M, D);
  // Other items go here
end;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top