带tLabel子项的FireMonkey tRectangle [英] FireMonkey tRectangle with tLabel child

查看:85
本文介绍了带tLabel子项的FireMonkey tRectangle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写基于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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆