首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >允许将键盘输入到嵌套在FireMonkey TEdit中的FireMonkey TPopup中

允许将键盘输入到嵌套在FireMonkey TEdit中的FireMonkey TPopup中
EN

Stack Overflow用户
提问于 2014-01-02 19:31:37
回答 4查看 2.4K关注 0票数 4

我很难让FireMonkey TEdit嵌套在FireMonkey TPopup中,以接收键盘输入。桌面和移动项目都会出现这种情况,尽管我对后者很感兴趣:

  1. 创建一个新的FMX项目。
  2. 向表单中添加TButtonTPopup,向TPopup添加TEdit
  3. 将弹出的Placement属性设置为plCenter,将其PlacementTarget设置为Button1
  4. 通过将弹出的IsOpen属性设置为True来处理按钮的True事件。
  5. 运行项目,单击/点击按钮,然后尝试在“编辑”控件中输入文本。

有什么想法吗?正确的答案当然可能是:键盘输入不受支持,但文档没有说明这两种方式。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2014-11-27 15:43:31

键盘输入似乎不适用于TPopup。一个简单的解决方案是使用TForm作为弹出表单:

代码语言:javascript
复制
unit Popup;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, FMX.Edit;

type
  TfmPopup = class(TForm)
    Edit1: TEdit;
    Panel1: TPanel;
    procedure FormDeactivate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
  private
  protected
  public
  end;

var
  fmPopup: TfmPopup;

implementation

{$R *.fmx}

procedure TfmPopup.FormDeactivate(Sender: TObject);
begin
  Close;
end;

procedure TfmPopup.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
  if Key = vkEscape then begin
    Close;
  end;
end;

end.

表格资源:

代码语言:javascript
复制
object fmPopup: TfmPopup
  Left = 0
  Top = 0
  BorderStyle = None
  Caption = 'Form1'
  ClientHeight = 94
  ClientWidth = 142
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop, iPhone, iPad]
  OnDeactivate = FormDeactivate
  OnKeyDown = FormKeyDown
  DesignerMobile = False
  DesignerWidth = 0
  DesignerHeight = 0
  DesignerDeviceName = ''
  DesignerOrientation = 0
  DesignerOSVersion = ''
  object Panel1: TPanel
    Align = Client
    Height = 94.000000000000000000
    Width = 142.000000000000000000
    TabOrder = 1
    object Edit1: TEdit
      Touch.InteractiveGestures = [LongTap, DoubleTap]
      TabOrder = 1
      Position.X = 20.000000000000000000
      Position.Y = 32.000000000000000000
      Width = 100.000000000000000000
      Height = 22.000000000000000000
    end
  end
end

当然,您可以改进这个简单的示例:不要将TEdit放在此表单上,而是继承此表单并将编辑放在那里。例如:

代码语言:javascript
复制
TfmMyPopup = class(TfmPopup)
  Edit1: TEdit;
private
protected
public
end;

使用一些特性来改进TfmPopup的基类,如TPopup:例如放置。您可以使用TfmPopup中从未显示的TfmPopup来使用TPopup的放置例程,而无需重写这段代码。

票数 1
EN

Stack Overflow用户

发布于 2015-04-03 13:54:19

有同样的问题,但固定的行为很少覆盖。将格式更改为TFormStyle.Normal并处理OnDeactivate事件。

代码语言:javascript
复制
    TPopup2 = class(TPopup)

    protected
      function CreatePopupForm: TFmxObject; override;
    end;

    TPopupForm2 = class(TCustomPopupForm)

    private
      procedure OnDeactivateEvent(Sender: TObject);
    public
      constructor CreateNew(AOwner: TComponent; Dummy: NativeInt = 0); override;
    end;

function TPopup2.CreatePopupForm: TFmxObject;
var
  NewStyle: TStyleBook;
  NewForm: TPanelForm;
begin
  NewForm := nil;
  try
    if not Assigned(StyleBook) and Assigned(Scene) then
      NewStyle := Scene.GetStyleBook
    else
      NewStyle := StyleBook;
    NewForm := TPopupForm2.Create(Self, NewStyle, PlacementTarget);
  except
    FreeAndNil(NewForm);
    Raise;
  end;
  Result := NewForm;
end;

constructor TPopupForm2.CreateNew(AOwner: TComponent; Dummy: NativeInt);
begin
  inherited;
  BeginUpdate;
  try
    FormStyle := TFormStyle.Normal;
    BorderStyle := TFmxFormBorderStyle.None;
    Fill.Kind := TBrushKind.None;
    Transparency := True;
    OnDeactivate := OnDeactivateEvent;
  finally
    EndUpdate;
  end;

end;

procedure TPopupForm2.OnDeactivateEvent(Sender: TObject);
begin
  Close;
end;
票数 2
EN

Stack Overflow用户

发布于 2014-01-02 20:46:41

使用Popup1.popup(true)而不是更改isOpen属性

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

https://stackoverflow.com/questions/20890373

复制
相关文章

相似问题

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