【问题标题】:Custom Firemonkey style - linking properties between control and style?自定义 Firemonkey 样式 - 控件和样式之间的链接属性?
【发布时间】:2016-03-08 18:01:24
【问题描述】:

德尔福 XE-6

我正在尝试为 TGroupBox 控件创建自己的样式。

我查看了许多演示和教程,但似乎无法弄清楚这一点。

如何使控件中的文本变为空白并显示在样式的文本控件上?

我知道它与 StyleName 有关,但我不知道我做错了什么。

谁能提供一个简单的例子? 例如,一个 TGroupbox - 在顶部有一个标题,但是如果你想把它放在一个从顶部向下的横幅上怎么办。我可以创建横幅,但是如何将横幅上的文本项与控件的标题属性链接?

感谢

【问题讨论】:

    标签: delphi firemonkey firemonkey-style


    【解决方案1】:

    您不必自己进行链接。

    FireMonkey 控件自行完成:

    function TPresentedTextControl.FindTextObject: TFmxObject;
    begin
      Result := FindStyleResource('text'); // Do not localize
    end;
    

    确保样书中的文本控件名为 text

    我做了一个这样的小例子:

    object TStyleContainer
      object TLayout
        StyleName = 'grouboxstylebottom'
        Padding.Left = 2.000000000000000000
        Padding.Top = 8.000000000000000000
        Padding.Right = 2.000000000000000000
        Padding.Bottom = 2.000000000000000000
        Position.X = 410.000000000000000000
        Position.Y = 360.000000000000000000
        Size.Width = 120.000000000000000000
        Size.Height = 100.000000000000000000
        Size.PlatformDefault = False
        Visible = False
        TabOrder = 0
        object TStyleObject
          StyleName = 'background'
          Align = Client
          CapMode = Tile
          Locked = True
          SourceLookup = 'Windows 10 Desktopstyle.png'
          Size.Width = 116.000000000000000000
          Size.Height = 90.000000000000000000
          Size.PlatformDefault = False
          WrapMode = Tile
          SourceLink = <
            item
              CapInsets.Left = 2.000000000000000000
              CapInsets.Top = 2.000000000000000000
              CapInsets.Right = 2.000000000000000000
              CapInsets.Bottom = 2.000000000000000000
              SourceRect.Left = 166.000000000000000000
              SourceRect.Top = 83.000000000000000000
              SourceRect.Right = 213.000000000000000000
              SourceRect.Bottom = 130.000000000000000000
            end>
          object TPanel
            StyleName = 'banner'
            Align = Bottom
            Position.Y = 70.000000000000000000
            Size.Width = 116.000000000000000000
            Size.Height = 20.000000000000000000
            Size.PlatformDefault = False
            TabOrder = 0
          end
          object TText
            StyleName = 'text'
            Align = Bottom
            ClipParent = True
            Locked = True
            HitTest = False
            Margins.Left = 1.000000000000000000
            Margins.Top = 2.000000000000000000
            Margins.Right = 1.000000000000000000
            Margins.Bottom = -15.000000000000000000
            Position.X = 1.000000000000000000
            Position.Y = 70.146484375000000000
            Size.Width = 114.000000000000000000
            Size.Height = 14.853515625000000000
            Size.PlatformDefault = False
            Text = 'Groupbox'
            TextSettings.Font.Family = 'Showcard Gothic'
            TextSettings.WordWrap = False
          end
        end
      end
    end
    

    所以最终的控制会是这样的:

    在这种情况下,将 GroupBox 的 StyleLookup 设置为 groupboxstylebottom

    【讨论】:

    • 啊,明白了!正是我想要的 - 谢谢!
    猜你喜欢
    • 1970-01-01
    • 2013-06-26
    • 2011-09-09
    • 1970-01-01
    • 2014-10-18
    • 2018-04-20
    • 2018-03-22
    • 2011-02-27
    • 2015-01-23
    相关资源
    最近更新 更多