在文本框中我想只输入数字,而不是使用csharp输入如何验证的字符

问题描述:

在文本框中我想只输入数字,而不是使用csharp输入如何在Windows应用程序中验证的字符。



i有一个文本框,如下所示;





分配小时文本框





在该文本框中我想只键入不是字符的数字。





如何在Windows应用程序中使用csharp进行验证。



请帮帮我。



注意:这是windows应用程序。



我该怎么办。请帮助我。

in textbox i want to enter only numbers,not characters using csharp how to validate in windows application.

i have one textbox called as follows;


Allocated Hrs textbox


in that textbox i want to type only numbers not characters.


for that how to validate using csharp in windows application.

please help me.

Note : it is windows application.

how can i do.please help me.




Hi
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!char.IsNumber(e.KeyChar))
    {
        e.Handled = false;
    }
}





问候

Jegan



Regards
Jegan

>

你可以通过2种方式完成。



1.使用整数输入框或蒙面文本框(仅限整数的掩码)



2.你可以编写一个用语法验证的函数



you can do it by 2 ways.

1. Use integer input box or masked text box (mask for integers only)

2. You can write a function for validating with syntax

int temp =0 ;
if(!int.TryParse(textbox1.text.Trim(),out temp))
MessageBox.Show("Enter integers only");


简单数字文本框 [ ^ ]