首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有tLabel子级的FireMonkey tRectangle

具有tLabel子级的FireMonkey tRectangle
EN

Stack Overflow用户
提问于 2019-09-07 02:48:26
回答 1查看 276关注 0票数 0

我正在编写一个基于tRectangle的自定义控件

代码语言:javascript
复制
tMyRect = class (tRectangle)

tMyRect Constructor上,我创建了一个tLabel

代码语言:javascript
复制
fRectLabel := tLabel.Create (Self);

然后为它设置一些属性。

在运行时,tLabel不会根据属性设置显示,也不会响应快捷键。

下面是完整的代码:

代码语言:javascript
复制
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的行为不像预期的那样,我将非常感谢。

EN

回答 1

Stack Overflow用户

发布于 2019-09-07 06:30:17

您需要更改TLabel的StyleSettings属性,以便样式系统不会应用您所更改的属性,例如:

代码语言:javascript
复制
  StyledSettings := StyledSettings - [TStyledSetting.FontColor, TStyledSetting.Style];

至于“两者都不响应快捷键”部分,您需要澄清您的意思,因为您还没有显示与此相关的代码

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57827205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档