在应用程序中更改字体

时间:2015-09-22 09:32:38

标签: delphi fonts firemonkey

有没有简单的方法来改变整个程序中的字体?我有桌面fmx(delphi xe7)应用程序,它使用样式,但对于某些用户来说,配置这个东西是必要的。

我明白并且它可能看起来像这样:

LabelReceptSign.StyledSettings := [];
LabelReceptSign.FontColor:= ComboColorBox1.Color;
LabelReceptSign.Font.Size:= SpinBoxReceptFontsize.Value;
LabelReceptSign.Font.Family:= ComboBoxFontRec.Selected.Text;

对于每个组件,但它将是一个非常庞大的代码!使用FindComponent过程和名称itteration生成'label'+ inttost(i)我可以缩短它,但不管它是什么方式都很差。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

好吧,我写了代码,它正在工作,除了comboedit和radiobutton - 我不知道为什么,但在另一个程序中改变它们。我也不知道如何处理mainmenu。该过程仅更改弹出菜单项。

Procedure FontchangeApply;
   var
i : integer;
begin

if Programfont.usefont = true  then begin

 with form2 do begin
   for i := 0 to form2.ComponentCount-1 do begin
    try
       if  ContainsText(Components[i].Name, 'label') then begin
             (Components[i] as TLabel).StyledSettings:= [];
                   (Components[i] as TLabel).font.Size:=    programfont.programfont.Size;
                (Components[i] as TLabel).font.family:= programfont.programfont.family;
                (Components[i] as TLabel).fontcolor:= programfont.programfontcolor;
          end;

          if  ContainsText(Components[i].Name, 'stringgrid') then begin
              (Components[i] as Tstringgrid).StyledSettings:= [];
              (Components[i] as Tstringgrid).TextSettings.font.Size:= programfont.programfont.Size;
              (Components[i] as Tstringgrid).TextSettings.font.family:= programfont.programfont.family;
              (Components[i] as Tstringgrid).TextSettings.fontcolor:= programfont.programfontcolor;
           end;

          if  ContainsText(Components[i].Name, 'button') then begin
           (Components[i] as Tbutton).StyledSettings:= [];
           (Components[i] as Tbutton).font.Size:= programfont.programfont.Size;
           (Components[i] as Tbutton).font.family:= programfont.programfont.family;
           (Components[i] as Tbutton).fontcolor:= programfont.programfontcolor;
          end;

         if  ContainsText(Components[i].Name, 'Menuitem') then begin
           (Components[i] as TMenuitem).StyledSettings:= [];
           (Components[i] as TMenuitem).font.Size:= programfont.programfont.Size;
           (Components[i] as TMenuitem).font.family:= programfont.programfont.family;
           (Components[i] as TMenuitem).fontcolor:= programfont.programfontcolor;
         end;

        if  ContainsText(Components[i].Name, 'Tabitem') then begin
           (Components[i] as TTabitem).StyledSettings:= [];
           (Components[i] as TTabitem).font.Size:= programfont.programfont.Size;
           (Components[i] as TTabitem).font.family:= programfont.programfont.family;
           (Components[i] as TTabitem).fontcolor:= programfont.programfontcolor;
        end;

        if  ContainsText(Components[i].Name, 'DateEdit') then begin
           (Components[i] as TDateEdit).StyledSettings:= [];
           (Components[i] as TDateEdit).font.Size:= programfont.programfont.Size;
           (Components[i] as TDateEdit).font.family:= programfont.programfont.family;
           (Components[i] as TDateEdit).fontcolor:= programfont.programfontcolor;
        end;

        if  ContainsText(Components[i].Name, 'TimeEdit') then begin
           (Components[i] as TTimeEdit).StyledSettings:= [];
           (Components[i] as TTimeEdit).font.Size:= programfont.programfont.Size;
           (Components[i] as TTimeEdit).font.family:= programfont.programfont.family;
           (Components[i] as TTimeEdit).fontcolor:= programfont.programfontcolor;
        end;

        if  ContainsText(Components[i].Name, 'Spinbox') then begin
           (Components[i] as TSpinbox).StyledSettings:= [];
           (Components[i] as TSpinbox).font.Size:= programfont.programfont.Size;
           (Components[i] as TSpinbox).font.family:= programfont.programfont.family;
           (Components[i] as TSpinbox).fontcolor:= programfont.programfontcolor;
        end;

        if  ContainsText(Components[i].Name, 'Memo') then begin
           (Components[i] as TMemo).StyledSettings:= [];
           (Components[i] as TMemo).font.Size:= programfont.programfont.Size;
           (Components[i] as TMemo).font.family:= programfont.programfont.family;
           (Components[i] as TMemo).fontcolor:= programfont.programfontcolor;
        end;

        if  ContainsText(Components[i].Name, 'Checkbox') then begin
           (Components[i] as TCheckbox).StyledSettings:= [];
           (Components[i] as TCheckbox).font.Size:= programfont.programfont.Size;
           (Components[i] as TCheckbox).font.family:= programfont.programfont.family;
           (Components[i] as TCheckbox).fontcolor:= programfont.programfontcolor;
        end;

        if  ContainsText(Components[i].Name, 'Edit') then begin
           (Components[i] as TEdit).StyledSettings:= [];
           (Components[i] as TEdit).font.Size:= programfont.programfont.Size;
           (Components[i] as TEdit).font.family:= programfont.programfont.family;
           (Components[i] as TEdit).fontcolor:= programfont.programfontcolor;
        end;

       if  ContainsText(Components[i].ClassName, 'ComboEdit') then begin
             //showmessage('nashel comboedit');
           (Components[i] as TCustomComboEdit).StyledSettings:= [];
           (Components[i] as TCustomComboEdit).font.Size:= programfont.programfont.Size;
           (Components[i] as TEdit).font.family:= programfont.programfont.family;
           (Components[i] as TEdit).fontcolor:= programfont.programfontcolor;
        end;

        if  ContainsText(Components[i].Name, 'GroupBox') then begin
           //showmessage('nashel groupbox');
           (Components[i] as TGroupBox).StyledSettings:= [];
           (Components[i] as TGroupBox).font.Size:= programfont.programfont.Size;
           (Components[i] as TGroupBox).font.family:= programfont.programfont.family;
           (Components[i] as TGroupBox).fontcolor:= programfont.programfontcolor;
        end;

        if  ContainsText(Components[i].Name, 'RadioButton') then begin
            showmessage('nashel radiobutton');
           (Components[i] as TRadiobutton).StyledSettings:= [];
           (Components[i] as TRadiobutton).textsettings.font.Size:= programfont.programfont.Size;
           (Components[i] as TRadiobutton).textsettings.font.family:= programfont.programfont.family;
           (Components[i] as TRadiobutton).textsettings.fontcolor:= programfont.programfontcolor;
        end;

      except
        showmessage('Error in'+ Components[i].Name);
       end;
     end;

   end;
   end;
  end;