gpt4 book ai didi

delphi - 更改应用程序中的字体

转载 作者:行者123 更新时间:2023-12-02 09:51:49 24 4
gpt4 key购买 nike

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

我知道它可能看起来像这样:

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

对于每个组件来说,但这将是一个非常巨大的代码!使用 FindComponent 过程和名称迭代生成 'label' + inttost(i) 我可以使其更短,但无论如何这是非常糟糕的方式。

有什么建议吗?

最佳答案

嗯,我写了代码,它正在工作,除了组合编辑和单选按钮 - 我不知道为什么,但在另一个过程中更改它们。我也不知道如何处理主菜单。该过程仅更改弹出菜单项。

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;

关于delphi - 更改应用程序中的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32713392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com