欢迎光临
我们一直在努力

如何实现应用程序中的”回车”成tab?_delphi教程

建站超值云服务器,限时71元/月

 如何实现应用程序中的”回车”成TAB?

也就是说当按Enter键的时候,产生的效果是按了Tab键. 

下面是我经常使用的方法:

在你的数据模块中,添加如下代码:

interface

  。。。。。。

  type

    TMessageHandler = class     //使得回车消息转换成Tab消息

      class procedure AppMessage(var Msg:TMsg;var Handled:Boolean);

end; 

implementation

 

class procedure TMessageHandler.AppMessage(var Msg: TMsg; var Handled: Boolean);

begin

  if Msg.message=WM_KEYDOWN then

    if (Msg.wParam=VK_RETURN ) and

      (

        (Screen.ActiveForm.ActiveControl is TEdit) or               

        (Screen.ActiveForm.ActiveControl is TComboBox) or

        (Screen.ActiveForm.ActiveControl is TCheckBox) or

        (Screen.ActiveForm.ActiveControl is TRadioButton)

              //可以添加需要的控件

      )

    then

    begin

      Msg.wParam:=VK_TAB;

    end

    else if (Msg.wParam=VK_RETURN) and

      (

       (Screen.ActiveForm.ActiveControl is TDBGrid)

      )

    then

    begin

      with Screen.ActiveForm.ActiveControl do

      begin

        if Selectedindex<(FieldCount-1) then

          Selectedindex:=Selectedindex+1{ 移动到下一字段}

        else

          Selectedindex:=0;

      end;

    end;

end;

为了使得整个应用程序都能够实现主要的功能,在主窗体的OnCreate事件中添加如下代码: 

procedure TfmMain.FormCreate(Sender: TObject);

begin

    Application.OnMessage:=TMessageHandler.AppMessage;

end; 

到此为止,你的应用程序已经实现了这个Enter->Tab的转换.

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 如何实现应用程序中的”回车”成tab?_delphi教程
分享到: 更多 (0)