用键盘控制光标在输入框中跳转的小巧门 (轉自http://blog.csdn.net/dhlhh)

来源:互联网 发布:java代码调用存储过程 编辑:程序博客网 时间:2024/05/29 21:28

SendKeys.Send("+{TAB}");

举例:
private void txtMInfo_KeyDown(object sender, KeyEventArgs e)
{
        
// 向后跳转
        if ( e.KeyCode == Keys.Enter || e.KeyCode == Keys.Right )
        {
                
SendKeys.Send("{TAB}");
        }
        
// 向前回跳
        else if ( e.KeyCode == Keys.Left || e.KeyCode == Keys.Up )
        {
                
SendKeys.Send("+{TAB}");
        }
}

 很简单吧,不过很实用是吧。

今天心情比较好,刚为发现一个键盘控制的小巧门而高兴。
很多文章都有类似的介绍,如按ENTER键,光标移动至下一格之类的文章。
可是,以前还一直不知道,怎样开倒车,即光标要回到前一个控件上。

我就喜欢瞎磨,用Google,搜索不到,就知己磨吧。我开始乱按键,可是怎么也不会倒退。后来想到TAB键,用控制键加TAB键试试。
Ctrl + TAB、Alt + TAB,哈哈,就是:SHIFT + TAB

马上用SendKeys,查SHIFT +TAB是怎么写。还是有些麻烦,帮助中是 +(EC)之类的。
胡乱的试,{+TAB}、{+{TAB}}、{+}{TAB}......,总之能想到的组合都想到了,都试了
成功:
正确写法:

<script type="text/javascript"><!--google_ad_client = "pub-1345733517560605";google_ad_width = 728;google_ad_height = 90;google_ad_format = "728x90_as";google_ad_type = "text_image";google_ad_channel = "";google_ui_features = "rc:6";//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击