检查文本框内的文本 [英] Check the Text within textbox
本文介绍了检查文本框内的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
Hi all,
How could we check the text at the time of entering the text in textbox, whether it is String or Int ?
推荐答案
当然总是 我>一个字符串.但是,您可以使用例如 Int32.TryParse > [ ^ ].
Of course it is always a string. However you may check if such string can be parsed to a number, using, for instance Int32.TryParse[^].
检查此
Hi ,
Check this
private void button1_Click(object sender, EventArgs e)
{
TryToParse(textBox1.Text);
}
void TryToParse(string value)
{
int number;
bool result = Int32.TryParse(value, out number);
if (result)
{
MessageBox.Show("Number");
}
else
{
MessageBox.Show("String");
}
}
最好的问候
M.Mitwalli
Best Regards
M.Mitwalli
尝试一下:-
Try This:-
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar >= ''a'' && e.KeyChar <= ''z'') || (e.KeyChar >= ''A'' && e.KeyChar <= ''Z''))
{
e.Handled = true;
MessageBox.Show("Int Entered.", "TextBox Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("String Entered.", "TextBox Message", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
这篇关于检查文本框内的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文