DELPHI方面输入EDIT

procedure TForm1.FormCreate(Sender: TObject);

var

 i:integer;

begin

 for i:=0 to ComponentCount-1 do

     if Components[i] is TEdit then

       (Components[i] as TEdit).OnKeyPress:=EditKeyPress;

end;

 

procedure TForm1.EditKeyPress(Sender: TObject; var Key: Char);

var

 Index:integer;

begin

 if key=#13 then

 begin

    if ActiveControl.ComponentIndex < ComponentCount-1 then

      Index:=ActiveControl.ComponentIndex+1

    else

      Index:=ComponentCount-1;

    while (not (Components[Index] is TEdit)) and (Index < ComponentCount) do

    begin

      Index:=Index+1;

    end;

    (Components[Index] as TEdit).SetFocus;

    (Components[Index] as TEdit).SelectAll;

 end;

end;

这里我们利用了窗体的ActiveControl属性,它代表当前获得焦点的输入文本框;ComponentIndex属性代表了窗体控件放置的次序,也作为本方法中输入框获得焦点的顺序的参考。这个例子所使用方法的难点在于窗体上可以获得焦点的控件也许不止文本框,还有按钮、列表框、复选框等等,如何区分它们需要用到Delphi的运行时信息(RTTI)。另外,该方法有一个局限就是获得焦点的顺序和设计时控件放置的顺序相关。

转载于:https://www.cnblogs.com/chengxin1982/archive/2009/03/13/1410118.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值