问题描述
我正在编写基于tRectangle
的自定义控件:
I am coding a custom control based on tRectangle
:
tMyRect = class (tRectangle)
在tMyRect Constructor
上,我创建一个tLabel
:
fRectLabel := tLabel.Create (Self);
,然后为其设置一些属性.
and then set some properties for it.
在运行时,不会根据属性设置显示tLabel
,也不会响应快速键.
At runtime, the tLabel
is not showed according to the properties settings, neither responds to the speedkey.
遵循完整的代码:
unit frmMyRect;
interface
uses FMX.Controls, FMX.Controls.Presentation, FMX.Forms, FMX.Layouts,
FMX.Objects, FMXFMX.StdCtrls, FMX.Types,System.Classes, System.UITypes;
type
tfrmMyRect = class (tForm)
procedure FormCreate (Sender: tObject);
end;
tMyRect = class (tRectangle)
fRectLabel : tLabel;
constructor Create (aOwner: tComponent);
end;
var formMyRect: tfrmMyRect;
implementation
{$R *.fmx}
var MyRect : tMyRect;
procedure tformMyRect.FormCreate (Sender: tObject);
begin
MyRect := tMyRect.Create (Self);
MyRect.Parent := frmMyRect;
end; { FormCreate }
constructor tMyRect.Create (aOwner: tComponent);
begin
inherited;
Align := tAlignLayout.Center;
CanFocus := True;
Height := 23;
Width := 80;
fRectLabel := tLabel.Create (Self);
with fRectLabel do begin
Align := tAlignLayout.Center;
AutoSize := True;
FocusControl := Self;
HitTest := True;
Parent := Self;
Text := 'Labe&l';
with TextSettings do begin
FontColor := TAlphaColorRec.Blue;
WordWrap := False;
Font.Style := [TFontStyle.fsBold];
end;
end;
end; { Create }
end.
我很高兴有人可以澄清为什么tLabel
的行为不符合预期.
I appreciate if someone can clarify why the tLabel
does not behave as expected.
推荐答案
您需要更改TLabel的StyleSettings属性,以便样式系统不会应用您已更改的样式,例如:
You need to alter the StyleSettings property of the TLabel so that the styling system does not apply those that you have changed, e.g.:
StyledSettings := StyledSettings - [TStyledSetting.FontColor, TStyledSetting.Style];
对于都不响应快速键"部分,您需要弄清您的意思,因为您没有显示与此相关的代码
As to the "neither responds to the speedkey" part, you'll need to clarify what you mean, as you have not shown code related to that
这篇关于带tLabel子项的FireMonkey tRectangle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!