Chinaunix首页 | 论坛 | 博客
  • 博客访问: 495258
  • 博文数量: 60
  • 博客积分: 2673
  • 博客等级: 少校
  • 技术积分: 700
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-09 00:25
个人简介

目前主要从事C++软件开发

文章分类

全部博文(60)

文章存档

2013年(3)

2012年(3)

2010年(6)

2009年(23)

2008年(25)

我的朋友

分类:

2009-04-17 23:33:54

假设你有3个文本框需要进行快捷键设置,
1   向用户说明快捷键
假设label1对应的输入控件的快捷键为alt+1
this.label1.Text   =   "my   test(&1) ";
&符号会将后随的字符加下划线显示
2   将这些框的KeyDown   事件连接到textBox1_KeyDown函数

                        this.textBox1.KeyDown   +=   new   System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown);
                        this.textBox2.KeyDown   +=   new   System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown);
                        this.textBox3.KeyDown   +=   new   System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown);

3   编写按键处理程序
                private   void   textBox1_KeyDown(object   sender,   KeyEventArgs   e)
                {
                        if   (e.Alt)   //   当按下Alt时的处理
                        {
                                switch   (e.KeyCode)
                                {
                                        case   Keys.D1:   //   如果同时为数字0
                                                textBox1.Focus();
                                                e.Handled   =   true;
                                                break;
                                        case   Keys.D2:
                                                textBox2.Focus();
                                                e.Handled   =   true;
                                                break;
                                        case   Keys.D3:
                                                textBox3.Focus();
                                                e.Handled   =   true;
                                                break;
                                        default:
                                                break;
                                }
                        }
                }
阅读(1373) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~