文本框不接受“空格” ? [英] Text box will not accept "Space" ?
本文介绍了文本框不接受“空格” ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我需要限制文字框的空格按钮。意味着不想输入文本框的空格按钮。我正在使用带有c#的windows应用程序。
谢谢和问候,
Murali.K
Hi All,
I need to restrict "Space" button for text box. Means don''t want to give enter "Space" button for text box. I am using windows application with c#.
Thanks and Regards,
Murali.K
推荐答案
我试过像这样工作正常。
I tried like this it''s working fine.
if (txtDeathFirstName.Text.Length == 0 && e.KeyChar == ' ')
{
e.Handled = true;
}
else
{
e.Handled = false;
}
你可以把它添加到班级
You could just add this to the class
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
e.Handled = e.Key == Key.Space;
base.OnPreviewKeyDown(e);
}
你可以使用按键事件来做到这一点
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress.aspx [ ^ ]
检查字符代码并省略它:)
Hi,
you can do that using on key press event
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress.aspx[^]
Check char code and omit it :)
这篇关于文本框不接受“空格” ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文