本文介绍了C#Windows应用程序KeyPress事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在寻找KeyPress事件的代码.
Hi All,
I''m looking for code for a KeyPress event.
Can any help me or give me the code for KeyPress event for textbox?
推荐答案
public textbox1_KeyPress(object sender,KeyPressEventArgs e)
{
e.KeyChar=char.ToUpper(e.KeyChar);//converts the entered char to upper
}
如果要对按下的按键进行任何验证,则可以在keydown事件中进行验证,并将布尔值传递给keypress事件,根据布尔值可以执行所需的操作
希望对您有帮助!
if you want to do any validations of the pressed key,you can do it in keydown event and pass a boolean value to keypress event,based on the bool value you can perform the operation you need
Hope it helps!!
myEditBox.KeyPress += (sender, eventArgs) => {
MessageBox.Show(
"You can examime eventArgs to see what key is pressed and act accordingly (even cancel the press)");
};
这篇关于C#Windows应用程序KeyPress事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!