我怎样才能在我的Delphi应用程序中使用所有系统注册的主题/样式?

huangapple go评论59阅读模式
英文:

How can I use ALL system registered themes/styles in my Delphi App?

问题

使用 Vcl.Themes.TStyleManager.StyleNames,我只能访问项目选项(应用程序/外观)中启用的样式名称。

我如何列出在系统中注册的所有样式名称,并在 Delphi 11 中使其生效?

英文:

With Vcl.Themes.TStyleManager.StyleNames, I have access to just the style names enabled in the project options (Application/Appearance).

How can I list all of the style names registered in the system, and make it active in Delphi 11?

答案1

得分: 1

这是我如何用可用的样式填充TComboBox

procedure FillComboboxWithStyles;
var
  stylename: string;
begin
  for stylename in TStyleManager.StyleNames do
    CBVclStyles.Items.Add(stylename);
end;

要激活特定的样式,你可以使用TStyleManager.SetStyle(const Name: string)并传入样式的名称。例如,从TComboBox中选择的样式:

if (CBVclStyles.ItemIndex >= 0) then
  TStyleManager.SetStyle(CBVclStyles.Items[CBVclStyles.ItemIndex])
else
  ;// 处理未选择样式的情况

不要忘记在你的uses中添加Vcl.Themes

英文:

This is how I fill a TComboBox with the available styles:

procedure FillComboboxWithStyles;
var
  stylename: string;
begin
  for stylename in TStyleManager.StyleNames do
    CBVclStyles.Items.Add(stylename);
end;

To activate a certain style you fill TStyleManager.SetStyle(const Name: string) with the stylename. For example the selected one from the TComboBox.

if (CBVclStyles.ItemIndex >= 0) then
  TStyleManager.SetStyle(CBVclStyles.Items[CBVclStyles.ItemIndex])
else
  ;// handle a non-selected style

Don't forget Vcl.Themes in your uses.

答案2

得分: 0

你可以将样式文件(*.vsf文件位于C:\Program Files (x86)\Embarcadero\Studio\22.0\Redist\styles\vcl,22.0表示你的RAD Studio版本)与你的.EXE一起包括在内,然后在填充ComboBox时对它们进行迭代。然后在选择时使用TStyleManager.LoadFromFile从文件中手动加载样式。

这也将允许用户将自己的样式文件添加到安装程序中。

我相信这就是IDE所做的(除了它直接从文件夹中读取列表,因为样式的“安装”实际上只是使文件在已识别的位置可用)。

英文:

You can include the style files (*.vsf from C:\Program Files (x86)\Embarcadero\Studio\22.0\Redist\styles\vcl with 22.0 marking your RAD Studio version) along with (externally from) your .EXE and then iterate over them when you fill your ComboBox. Then manually load the style from the file with TStyleManager.LoadFromFile when selected.

This will also allow your user to add his own style files to the setup.

This, I believe, is what the IDE does (except that it reads the list directly from the folder, since there's no "installation" of a style other than making the file available in a recognized location).

huangapple
  • 本文由 发表于 2023年2月18日 21:47:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75493763.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定