码迷,mamicode.com
首页 > 其他好文 > 详细

一个修改过简化版的InputQuery

时间:2015-08-06 14:52:14      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:

主要是觉得在单输入的情况下, 原来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;
        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;

 

一个修改过简化版的InputQuery

标签:

原文地址:http://www.cnblogs.com/hs-kill/p/4707744.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!