INPUTBOX 被置窗体之后

今天在程序中用到INPUTBOX调用时候却发现INPUTBOX不见了?原来是跑到程序的后面了,看不见。

处理方法:自己写个inputbox函数以备调用.

 

function  InputQbox( const  ACaption, APrompt:  string ;
var  Value:  string ): Boolean;
var
Form: TForm;
Prompt: TLabel;
Edit: TEdit;
DialogUnits: TPoint;
ButtonTop, ButtonWidth, ButtonHeight: Integer;
begin
Result :
=  False;
Form :
=  TForm.Create(Application);
with  Form  do
    
try
      Canvas.Font :
=  Font;
      FormStyle:
= fsStayOnTop; // 加上这就OK了
      DialogUnits :
=  GetAveCharSize(Canvas);
      BorderStyle :
=  bsDialog;
      Caption :
=  ACaption;
      ClientWidth :
=  MulDiv( 180 , DialogUnits.X,  4 );
      Position :
=  poScreenCenter;
      Prompt :
=  TLabel.Create(Form);
      
with  Prompt  do
      
begin
        Parent :
=  Form;
        Caption :
=  APrompt;
        Left :
=  MulDiv( 8 , DialogUnits.X,  4 );
        Top :
=  MulDiv( 8 , DialogUnits.Y,  8 );
        Constraints.MaxWidth :
=  MulDiv( 164 , DialogUnits.X,  4 );
        WordWrap :
=  True;
      
end ;
      Edit :
=  TEdit.Create(Form);
      
with  Edit  do
      
begin
        Parent :
=  Form;
        Left :
=  Prompt.Left;
        Top :
=  Prompt.Top  +  Prompt.Height  +   5 ;
        Width :
=  MulDiv( 164 , DialogUnits.X,  4 );
        MaxLength :
=   255 ;
        Text :
=  Value;
        SelectAll;
      
end ;
      ButtonTop :
=  Edit.Top  +  Edit.Height  +   15 ;
      ButtonWidth :
=  MulDiv( 50 , DialogUnits.X,  4 );
      ButtonHeight :
=  MulDiv( 14 , DialogUnits.Y,  8 );
      
with  TButton.Create(Form)  do
      
begin
        Parent :
=  Form;
        Caption :
=   ' 确定 ' ;
        ModalResult :
=  mrOk;
        Default :
=  True;
        SetBounds(MulDiv(
38 , DialogUnits.X,  4 ), ButtonTop, ButtonWidth,
          ButtonHeight);
      
end ;
      
with  TButton.Create(Form)  do
      
begin
        Parent :
=  Form;
        Caption :
=   ' 取消 ' ;
        ModalResult :
=  mrCancel;
        Cancel :
=  True;
        SetBounds(MulDiv(
92 , DialogUnits.X,  4 ), Edit.Top  +  Edit.Height  +   15 ,
          ButtonWidth, ButtonHeight);
        Form.ClientHeight :
=  Top  +  Height  +   13 ;          
      
end ;
      
if  ShowModal  =  mrOk  then
      
begin
        Value :
=  Edit.Text;
        Result :
=  True;
      
end ;
    
finally
      Form.Free;
    
end ;
end ;

 

转载于:https://www.cnblogs.com/delphi2010/archive/2009/06/01/1493854.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值