自定义 Firemonkey 样式 - 控件和样式之间的链接属性?
Custom Firemonkey style - linking properties between control and style?
Delphi XE-6
我正在尝试为 TGroupBox 控件创建自己的样式。
我看了很多演示和教程,但似乎无法理解这一点。
如何使控件中的文本变为空白并显示在样式的文本控件上?
我知道这与样式名称有关,但我不知道我做错了什么。
有人可以提供一个简单的例子吗?
例如,一个 TGroupbox - 在顶部有一个标题,但是如果你想把它放在从顶部向下的横幅上怎么办。创建横幅我可以做,但是我如何才能 link 横幅上带有控件标题 属性 的文本项?
谢谢
您不必自己进行链接。
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
。
Delphi XE-6
我正在尝试为 TGroupBox 控件创建自己的样式。
我看了很多演示和教程,但似乎无法理解这一点。
如何使控件中的文本变为空白并显示在样式的文本控件上?
我知道这与样式名称有关,但我不知道我做错了什么。
有人可以提供一个简单的例子吗? 例如,一个 TGroupbox - 在顶部有一个标题,但是如果你想把它放在从顶部向下的横幅上怎么办。创建横幅我可以做,但是我如何才能 link 横幅上带有控件标题 属性 的文本项?
谢谢
您不必自己进行链接。
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
。