问题描述
我的表单中有一个TextBox
,并在其上添加了此事件:
I have a TextBox
in my form and I added this event on it:
private void txtValue_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show(e.KeyData.ToString());
}
但是,即使我在文本框中输入了小写字母,它也会始终打印字母的大写字母.请参见下图:
But it always prints the upper case of the letter even though I entered a lower case letter in the textBox. Please see image below:
我应该如何获得正确的显示?谢谢...
How should I get the right display? Thanks...
推荐答案
KeyDown
和KeyUp
使用KeyEventArgs
,这通过KeyData
属性公开了Keys
枚举.枚举不具有小写字母值的表示形式.
KeyDown
and KeyUp
use KeyEventArgs
, which exposes the Keys
enum via the KeyData
property. The enum does not have representation for lower-case alphabetic values.
http://msdn.microsoft.com /en-us/library/system.windows.forms.keys.aspx
KeyPress
事件允许您通过KeyPressEventArgs.KeyChar
获取按键的实际字符.
The KeyPress
event allows you to get the actual character of the key pressed via KeyPressEventArgs.KeyChar
.
private void txtValue_KeyPress(object sender, KeyPressEventArgs e)
{
MessageBox.Show(e.KeyChar.ToString());
}
这篇关于总是大写...(C#winforms)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!