Firemonkey TEdit高度

时间:2016-04-07 13:54:23

标签: delphi textbox height firemonkey

我正在使用Delphi Seattle,我的应用程序适用于Windows桌面。

我正在尝试更改TEdit的字体大小。因此,高度也被修改。在设计时,一切都运行良好,但是当我运行我的应用程序时,TEdit忽略高度修改并且文本被剪切。

我试图按照建议的here查找FixedHeight,但我找不到此属性。

是否可以改变TEdit Heigth?

3 个答案:

答案 0 :(得分:5)

这可以通过覆盖控件的AdjustFixedSize方法来解决。 正如@chrisrolliston所述,Removing a FMX control’s size restrictions并举例说明here

unit Unit4;
interface
uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Edit, MyTEdit;

type
  TForm4 = class(TForm)
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
  end;

var
  Form4: TForm4;

implementation

{$R *.fmx}

procedure TForm4.FormCreate(Sender: TObject);
begin
  Edit1.Height := 60;
end;

end.
unit MyTEdit;
interface
uses
  FMX.Edit, FMX.Controls;

type
  TEdit = class(FMX.Edit.TEdit)
  protected
    procedure AdjustFixedSize(const Ref: TControl); override;
  end;

implementation
uses
  FMX.Types;

procedure TEdit.AdjustFixedSize(const Ref: TControl);
begin
  SetAdjustType(TAdjustType.None);
end;

end.

答案 1 :(得分:1)

如果你不想创建自己的Edit,那么处理这个问题的另一种方法是使用作弊演员来执行此操作。这使您可以访问受保护的编辑方法(SetAdjustType)。以下示例假定您具有名为wwedit3的编辑。

type
  THackStyledControl = class(TStyledControl);

procedure TValidationDemoForm.FormCreate(Sender: TObject);
begin
  wwedit3.ApplyStyleLookup; // Necessary or AdjustType gets overwritten
  THackStyledControl(wwedit3)  // Removes fixed height
        .SetAdjustType(TAdjustType.None);
  wwedit3.height:= 60; // Reset the height to desired value
end;

这样可行,但是如果您正在编写大小的硬件,则需要显式重置您的高度属性,如上面的代码所示。如果您使用align属性来定位编辑控件,那么您不需要将wwedit3。height设置为60

的附加行。

答案 2 :(得分:1)

如果您在StyleBook中使用样式:

  1. 首先在EditBox中检查样式名称-在“对象”检查器中查看TEdit的StyleLookup。如果为空,则表示Editbox的默认值为editstyle。您应该以样式搜索此名称。
  2. 打开当前样式,选择平台,在样式列表中找到editstyle
  3. FixedHeight更改为0。也可以设置Align = None重置对齐高度。
相关问题