我的用户可以在组合框中输入一些文本,但我希望这个文本自动以大写字母显示(就像用户有大写锁定一样)。任何想法如何做到这一点?c#窗体大写字母
Q
c#窗体大写字母
1
A
回答
6
您将需要处理KeyPress
事件。
private void ComboBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar >= 'a' && e.KeyChar <= 'z')
e.KeyChar -= (char)32;
}
32只是小写字母和大写字母之间ASCII值的区别。
1
您可以注册到TextChanged事件并将文本转换为大写。
private void combobox_TextChanged(object sender, EventArgs e)
{
string upper = combobox.Text.ToUpper();
if(upper != combobox.Text)
combobox.Text = upper;
}
1
另一个例子
private void TextBox_Validated(object sender, EventArgs e)
{
this.TextBox.Text = this.TextBox.Text.ToUpper();
}
问候
0
这是我如何处理它,它比简单地更换整个文本更加平滑变化。
private void ComboBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsLetter(e.KeyChar))
{
int p = this.SelectionStart;
this.Text = this.Text.Insert(this.SelectionStart, Char.ToUpper(e.KeyChar).ToString());
this.SelectionStart = p + 1;
}
}
相关问题
- 1. 字体小写字母,只是较小的大写字母
- 2. 大写字母小写函数C
- 3. C#计数每个大写字母和每个小写字母
- 4. 在C++中将小写字母转换为大写字母
- 5. C++,接受变量中的小写字母和大写字母
- 6. 大写字母和小写字母
- 7. 标识大写字母三联体
- 8. 大写字母,小写字母,大写的Ant属性
- 9. X86 NASM将大写字母转换为大写字母和小写字母
- 10. php大写字母大写字
- 11. 首字母大写的字符串首字母大写
- 12. 首字母大写
- 13. 以大写字母
- 14. 用大写字母
- 15. 大写首字母
- 16. 如何小写字母转换为大写字母和大写字母为小写字母
- 17. 大写小写字母
- 18. C#Windows窗体标签字体大小
- 19. C#:首字母大写的方法名?
- 20. 始终用大写字母...(C#的WinForms)
- 21. C使第一个字母大写
- 22. 反转C中的字母大小写
- 23. Lowecase在C中的大写字母
- 24. 带有大写字母的大写字母笔画
- 25. TextBlock与大写字母一样大(忽略字体ascender/descender)
- 26. 用小写字母写成小写字母大写
- 27. 大写字母的第一个字母
- 28. 用大写字母替换“ - ”字母
- 29. C长度不等的字符串,小写字母到大写字母
- 30. 在C中使用大写字母和小写字母对字符串排序
我觉得KeyChar是只读的,对于ComboBox ... –
@Edwin,没有 - KeyPressEventArgs既有getter和setter。 – Marlon
设置KeyChar从.NET 2.0开始有效 – Patrik