delphi 简化版的InputQuery 中文版输入对话框


本文整理自网络,侵删。

 
function _InputQuery(const ACaption: string; const APrompt: string; var AValue: string): Boolean;
  var
    nForm: TForm;
    nEdit: TEdit;
    nTop: Integer;
    nTextMetric: TTextMetric;
  begin
    Result := False;
    nForm := TForm.CreateNew(Application);
    with nForm do
    try
      Canvas.Font := Font;
      BorderStyle := bsDialog;
      Caption := ACaption;
      ClientWidth := 256;
      PopupMode := pmAuto;
      Position := poScreenCenter;
      nEdit := nil;

      GetTextMetrics(Canvas.Handle, nTextMetric);

      nTop := nTextMetric.tmAscent + 1;

      nEdit := TEdit.Create(nForm);
      with nEdit do
      begin
        Parent := nForm;
        Left := 8;
        Top := nTop;
        Width := nForm.ClientWidth - 16;
        MaxLength := 255;
        PasswordChar:='*'; // www.delphitop.com 改进
        Text := AValue;
        SelectAll;
        Inc(nTop, Height + 4);
      end;

      if APrompt <> '' then
      begin
        with TLabel.Create(nForm) do
        begin
          Parent := nForm;
          AutoSize := False;
          Caption := APrompt;
          Font.Color := clGrayText;
          Left := 8;
          Top := nTop;
          Width := nForm.ClientWidth - 16;
          WordWrap := False;
          Inc(nTop, Height + 15);
        end;
      end;

      with TButton.Create(nForm) do
      begin
        Parent := nForm;
        Caption := '确定';
        ModalResult := mrOk;
        Default := True;
        SetBounds(nForm.ClientWidth - Width * 2 - 8 - 4, nTop, Width, Height);
      end;
      with TButton.Create(nForm) do
      begin
        Parent := nForm;
        Caption := '取消';
        ModalResult := mrCancel;
        Cancel := True;
        SetBounds(nForm.ClientWidth - Width - 8, nTop, Width, Height);
        nForm.ClientHeight := Top + Height + nTextMetric.tmAscent;
      end;
      if ShowModal = mrOk then
      begin
        AValue := nEdit.Text;
        Result := True;
      end;
    finally
      nForm.Free;
    end;
  end;

相关阅读 >>

Delphi 62 进制的简单实现

Delphi tadoquery 中文使用说明

Delphi 安卓 app 动态权限申请

Delphi : tstringlist的find,indexof和sort

Delphi 2009 之 tstringbuilder 类[6]: equals

Delphi10.3构造一个json数据的第二种方法,并格式化输出

Delphi xe10 百度车牌识别

Delphi xe2获取文件的 md5、crc、sha-1、sha-256、sha-512

Delphi tchart 的使用

Delphi http 常见异常状态及Delphi idhttp 控件处理方式

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...