Firemonkey TEdit height

橙三吉。 提交于 2021-02-08 15:45:08

问题


I'm using Delphi Seattle and my application is for Windows Desktop.

I'm trying to change the font size of a TEdit. Consequently the height was also modified. At design time everything works well, but when I run my application TEdit ignores the height modification and the text is cut.

I've tried to find FixedHeight as suggested here, but I couldn't find this property.

Is it possible to change TEdit Heigth?


回答1:


This can be solved by overriding the control’s AdjustFixedSize method. As explained by @chrisrolliston, Removing a FMX control’s size restrictions and exemplified 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.



回答2:


If your're using styles in StyleBook:

  1. First check style name in EditBox - look at StyleLookup of TEdit in Object inspector. If it's empty, that means default editstyle for Editbox. You should search this name in styles.
  2. Open current style, select you platform, find editstyle in a list of styles.
  3. Change FixedHeight to 0. Also you can set Align = None to reset align height.



回答3:


Another way to handle this if you don't want to have to subclass and create your own Edit is to use a cheating cast to perform this. This gives you access to protected methods of Edit (SetAdjustType). The following example assumes you have a Edit named 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;

This will work, but if you are hard coding your sizes then you need to explicitly reset your height property as the code does above. If instead you are using the align property to position your edit controls, then you don't need the additional line that sets wwedit3.height to 60



来源:https://stackoverflow.com/questions/36478339/firemonkey-tedit-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!