2015-09-22 63 views
1

是否有任何簡單的方法可以在整個程序中更改字體?我有桌面fmx(delphi xe7)應用程序,它們使用樣式,但對於某些用戶來說,配置這個東西是必要的。更改應用程序中的字體

我understantand,它可能看起來像這樣:

​​

每個組件,但是這將是一個非常龐大的代碼!使用名稱迭代生成「標籤」+ inttost(i)的FindComponent過程我可以縮短它,但無論它是非常糟糕的方式。

有什麼建議嗎?

+0

出於好奇,爲什麼樣式不適合您的情況? –

+0

那麼,有7%的用戶投票在這個計劃中有這個機會。 –

+0

你可能會考慮尋找風格的鉤子。這使您可以自定義控件的繪製方式。請參閱https://theroadtodelphi.wordpress.com/2012/02/06/changing-the-color-of-edit-controls-with-vcl-styles-enabled/。 –

回答

0

嗯,我寫的代碼,它的工作,除了comboedit和單選按鈕 - 我不知道爲什麼,但改變他們在另一個程序。我也不知道如何處理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; 
相關問題