How to efficiently let a `ParentFont = False` child control to use same font name as parent?

前端 未结 3 875
说谎
说谎 2021-01-21 12:28

Most VCL controls has Fonts and ParentFont property. It is a good practice to set ParentFont = True and the Fonts will follow it\'s paren

3条回答
  •  别那么骄傲
    2021-01-21 13:05

    That is known VCL limitation.

    You can either have ParentFont or your custom font settings in which case changing font properties in parent will not be propagated.

    The best way around that is to use ParentFont = true everywhere and set custom font properties of specific controls at runtime in form's OnCreate event. Of course, in that case you lose What You See Is What You Get at design time, but you get more control over actual runtime appearance of your forms.

    procedure TForm1.OnCreate(Sender: TObject);
    begin
      inherited;
      Label1.Font.Style := [fsBold];
      Label1.Font.Color := clRed;
    end;
    

    For applying user custom font selection, you would also need to recreate forms, or use ParentFont := true before applying custom styles for specific controls, so they pick up your new font settings.

提交回复
热议问题