在文本框中不允许键入数字只允许字符uisng csharp [英] in textbox wont allow to type Numbers Only allow Characters uisng csharp
问题描述
不允许在Windows applciation中键入数字仅允许使用csharp的字符。
名称文本框。
在上面的文本框中,我不允许键入数字只允许字符。
表示如何验证。
假设当用户在文本框中键入数字时,想要显示消息Numbers not Allowed。
将记录保存到记录中,显示弹出消息。
我怎么能用csharp。请帮帮我。
谢谢和问候,
Narasiman P.
< blockquote> Hi
private void textBox1_KeyPress( object sender,KeyPressEventArgs e)
{
if ( !char.IsLetter(e.KeyChar))
{
e.Handled = false ;
}
}
问候
Jegan
它非常简单只需添加事件,您可以直接选择设计器或代码只需在构造函数中编写以下内容
textBox1.KeyPress + = new KeyPressEventHandler(textBox1_KeyPress);
private void textBox1_KeyPress( object sender,KeyPressEventArgs e)
{
if ( char .IsDigit( e.KeyChar)|| char .IsControl(e.KeyChar))
{
e.Handled = 真跨度>;
}
其他
{
e.Handled = false 跨度>;
}
}
hi professional
低于两个链接一用于数字限制和第二个用于角色.........
http://stackoverflow.com/questions/463299/how-do-i-make-a -textbox-only-accepted-numbers [ ^ ]
http://stackoverflow.com/questions/12607087/only-allow-specific-characters-in-textbox [ ^ ]
乐于助人。
in textbox wont allow to type Numbers Only allow Characters using csharp in windows applciation.
Name textbox.
In the above textbox i wont allow to type Numbers Only allow Characters.
for that how to validate.
suppose when user type the Numbers in the textbox, want to show the message "Numbers not Allowed".
before saving the record in to record, show the popup message.
for that how can i do using csharp. please help me.
Thanks & regards,
Narasiman P.
Hi
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsLetter(e.KeyChar)) { e.Handled = false; } }
Regards
Jegan
Its really simple just add event which you can directly select for designer or in code just write following in constructor
textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar)) { e.Handled = true; } else { e.Handled = false; } }
hi professional
below two link one for Numeric restriction and 2nd one for character.........
http://stackoverflow.com/questions/463299/how-do-i-make-a-textbox-that-only-accepts-numbers[^]
http://stackoverflow.com/questions/12607087/only-allow-specific-characters-in-textbox[^]
Happy to Help.
这篇关于在文本框中不允许键入数字只允许字符uisng csharp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!