C#windows应用程序按键事件问题 [英] C# windows application key press event problem

查看:95
本文介绍了C#windows应用程序按键事件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我尝试执行以下代码C#windows应用程序

Hi all,
I m tryng to do the following code C# windows application

 private void txtRollNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar=Keys.Enter)
}



但显示隐含转换是错误

请帮助





谢谢&问候

Indrajit


but is showing implicite conversion is error
Please help


Thanks & Regards
Indrajit

推荐答案

只需检查你的if语句..你实际上正在分配一个值..use ==而不是。

简单的错误。





希望它有所帮助!!
just check your if statement..you are actually assigning a value..use == instead.
simple mistake.


hope it helps!!


你需要将密钥转换为char并需要给==而不是=。



试试这个,

You need to cast the key to char and need to give == instead of =.

Try this,
if (e.KeyChar == (char)Keys.Enter)
{
//logic here

}


如果要比较相等性,请使用等于运算符 ==



Use the equality operator == if you want to compare for equality.

private void txtRollNumber_KeyPress(object sender, KeyPressEventArgs e)
{
 if (e.KeyChar == (char)Keys.Enter)
  {
  //Do your operation here
  }
}





现在它应该可以工作!



编辑:添加(char)将其强制转换为char类型。



Now its should work!

Edit : Added (char) to cast it to char type.


这篇关于C#windows应用程序按键事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆