【问题标题】:How do you change the Delphi FMX TBindNavigator Images?如何更改 Delphi FMX TBindNavigator 图像?
【发布时间】:2022-01-01 17:39:53
【问题描述】:

我想更改与 Delphi 的 FMX TBindNavigator 关联的默认图像。当我在 IDE 中右键单击 TBindNavigator 控件时,我看不到以下选项:

  • 编辑自定义样式...
  • 编辑默认样式...

如何更改与 TBindNavigator 关联的图像?

例如,我想让 FMX BindNavigator 看起来像 VCL DBNavigator

来自:

致此:

【问题讨论】:

  • TBindNavButtons 有一个属性Images,它是用于按钮的图像的 ImageList。我不知道这是否有帮助,但文档是 here
  • 编辑自定义样式...和编辑默认样式...似乎已在最近的 Delphi 中被删除(至少在我的 11 版本中它们没有出现)。可以在样式编辑器中加载一种可用样式,然后搜索他们感兴趣的控件的类名(不带 T 前缀),假设它的自定义样式可用。然后可以检查样式的结构并制作自定义版本,或者以编程方式即时更改样式对象。不知道他们是否是那样的风格。甚至可以使用文本编辑器打开样式文件并搜索 BindNavigator
  • ...但是,由于我猜这些按钮不是样式部分而是子组件,因此您可以通过 Controls 属性枚举它们(不幸的是,它们在不可见时会更改顺序)并为每个按钮设置一些 ImageList直接一个。要设置哪些可见,请参阅docwiki.embarcadero.com/Libraries/Sydney/en/…

标签: delphi firemonkey


【解决方案1】:

在 Delphi FMX 中,TBindNavigator 组件似乎不可自定义,因为它不公开任何样式属性,但可以对组件的源代码 (Fmx.Bind.Navigator.pas) 进行一些更改以覆盖其默认样式。请注意,这些更改仅在运行时可见,并且在 Delphi 11 上的空白项目上进行了测试。

  1. 默认情况下,TBindNavigator 中的按钮使用相同的 TCornerButton 样式,但您可以更改此设置,使其使用 TButton 的默认样式或其他自定义样式。找到TBindNavButton.GetDefaultStyleLookupName 函数并更改 Result 的值:

    Result := 'ButtonStyle';
    
  2. 按钮中的颜色都是相同的,因为组件使用 TCornerButton(或 TButton,如果如上修改)的文本颜色。要为每个按钮指定不同的颜色,请找到 TBindNavButton.ApplyStyle 过程并替换内容内部 if FPath <> nil then 检查类似这样的内容:

    case FIndex of
      nbFirst: FPath.Fill.Color := TAlphaColors.Blue;
      nbPrior: FPath.Fill.Color := TAlphaColors.Blue;
      nbNext: FPath.Fill.Color := TAlphaColors.Blue;
      nbLast: FPath.Fill.Color := TAlphaColors.Blue;
      nbInsert: FPath.Fill.Color := TAlphaColors.Firebrick;
      nbDelete: FPath.Fill.Color := TAlphaColors.Firebrick;
      nbEdit: FPath.Fill.Color := TAlphaColors.Blue;
      nbPost: FPath.Fill.Color := TAlphaColors.Forestgreen;
      nbCancel: FPath.Fill.Color := TAlphaColors.Firebrick;
      nbRefresh: FPath.Fill.Color := TAlphaColors.Blue;
      nbApplyUpdates: FPath.Fill.Color := TAlphaColors.Blue;
      nbCancelUpdates: FPath.Fill.Color := TAlphaColors.Blue;
    end;
    
  3. FMX TBindNavigator 不使用图像,而是使用矢量路径来呈现其图标,这些可以在与 SVG 格式的字符串相同的源文件中找到。要更改图标,您必须拥有其 SVG 数据并在 BtnTypePath 数组中替换其对应的字符串。例如,这里的编辑图标看起来像一张纸,被向上箭头取代,看起来更像 VCL 对应物:

    BtnTypePath: array[TBindNavigateBtn] of string = (
      ...
      // edit
      'M 291.667,346.113 L 316.667,311.738 L 341.236,346.113 Z ',  // Arrow pointing up
      ...
    );
    
  4. 图标的大小也在文件中进行了硬编码。要更改此设置,请找到 TCustomBindNavigator.InitButtons 过程并编辑以下行:

    Btn.FPath.Width := 12;   // Make them smaller
    Btn.FPath.Height := 12;  // Make them smaller
    

通过所有之前的更改,我们现在有了一个在运行时更类似于 VCL 对应物的栏。

【讨论】:

  • 亚历克斯,谢谢您的回答。这绝对是辉煌的。请给我你的电子邮件地址。 rileymj@zilchworks.com
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-08
  • 2021-08-17
  • 1970-01-01
  • 1970-01-01
  • 2015-08-17
  • 1970-01-01
  • 2021-06-07
相关资源
最近更新 更多