我正在编写一个基于tRectangle的自定义控件
tMyRect = class (tRectangle)在tMyRect Constructor上,我创建了一个tLabel
fRectLabel := tLabel.Create (Self);然后为它设置一些属性。
在运行时,tLabel不会根据属性设置显示,也不会响应快捷键。
下面是完整的代码:
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的行为不像预期的那样,我将非常感谢。
发布于 2019-09-07 06:30:17
您需要更改TLabel的StyleSettings属性,以便样式系统不会应用您所更改的属性,例如:
StyledSettings := StyledSettings - [TStyledSetting.FontColor, TStyledSetting.Style];至于“两者都不响应快捷键”部分,您需要澄清您的意思,因为您还没有显示与此相关的代码
https://stackoverflow.com/questions/57827205
复制相似问题