能不能使键盘按键和Form上的Button_Click对应起来 就是按下键盘上的某个键(除Enter,Esc键)时触发button1_Click事件 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void txtname_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if (Convert.ToInt32(e.KeyChar) == 13) { bool bFocus = this.txtpasswd.Focus(); bFocus = true; } }keypress 事件 // 先设置this.KeyPreview = true; private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e){ if( e.KeyValue == 27 ) // 如果是按下 Esc 键,触发 Button_Click 事件 { Button_Click( null, null ); }} 加如下的代码:this.KeyPreview = true; 重置在定义的变量写下面代码protected override bool ProcessDialogKey(Keys keyData) { if (keyData==Keys.F1) { 确定_ButtonClick(null,null); } if (keyData==Keys.Escape) { toolBar3_ButtonClick(null,null); } if (keyData==Keys.F9) { checkBox1.Checked=!checkBox1.Checked; } return base.ProcessDialogKey (keyData); } 关于C# 如何关闭Timer所执行的已阻塞的方法 如何手动添加列 问问啊问问 如何在程序中添加动画? 求关闭笔记本显示器的代码 怎样判断鼠标所在位置的像素的颜色? 利用DrawImageUnscaled画图,怎么旋转图的角度? C#中关于静态方法问题 如何使用C#和本地exe文件互相调用传参? 异常"未将对象引用设置到对象的实例",怎么办? 请问如何绑定数据 请教水晶报表设计的问题
{
if (Convert.ToInt32(e.KeyChar) == 13)
{
bool bFocus = this.txtpasswd.Focus();
bFocus = true;
}
}
keypress 事件
this.KeyPreview = true; private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if( e.KeyValue == 27 ) // 如果是按下 Esc 键,触发 Button_Click 事件
{
Button_Click( null, null );
}
}
this.KeyPreview = true;
在定义的变量写下面代码protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData==Keys.F1)
{
确定_ButtonClick(null,null);
}
if (keyData==Keys.Escape)
{
toolBar3_ButtonClick(null,null);
}
if (keyData==Keys.F9)
{
checkBox1.Checked=!checkBox1.Checked;
}
return base.ProcessDialogKey (keyData);
}