海友们,我有一个关于限制条件的问题 [英] hai friends ihave a question on restrict conditions

查看:78
本文介绍了海友们,我有一个关于限制条件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在windows文本框中编写接受10000以上和20000以下的代码





你能告诉我

感谢

how to write a code for accepting above 10000 and bellow 20000 in windows textbox


can you tell me
thankss

推荐答案

这个概念叫做验证,仅供参考。

你检查属性层的值(如果你有的话)一个)或点击按钮或你想要的地方你可以写一个简单的if..else ..语句来检查。

类似于 -

That concept is called validation, FYI.
You check the value at your property layer (if you have one) or on the button click or where ever you want you can just write a simple if..else.. statement to check that.
Something like-
try
{
  int yourValue=int.Parse(txtYourTb.Text);
  if(yourValue>10000 && yourValue<20000)
  {
     //do your stuff
  }
  else
  {
     MessageBox.Show("Invalid Input");
     return;
  }
}
catch(Exception ex)
{
   //str msg=ex.Message;
}





希望,它会有所帮助:)



Hope, it helps :)


就我个人而言,我不会 - 我会使用NumericUpDown。



但是,如果必须,你可以在验证事件 [ ^ ]当用户离开文本框或 TextChanged事件 [ ^ ]每次改变时都会发生。



无论哪种方式,都要使用 int.TryParse [ ^ ]将文本转换为数字,检查范围并报告或更改。
Personally, I wouldn't - I'd use a NumericUpDown instead.

But, if you must, you can either do it in the Validating event[^] which will occur when teh user leaves the textbox, or in the TextChanged event[^] which occurs each time it alters.

Either way, use int.TryParse[^] to convert the text to a number, check the range and report or alter it.


Quote:

if(Convert.ToInt32(TextBox1.Text)> 20000 || Convert.ToInt32(TextBox1.Text)< 10000)

{

MessageBox.Show(金额b / w 10000-20000);

TextBox1.Text =;

返回;

}

if (Convert.ToInt32(TextBox1.Text) > 20000 || Convert.ToInt32(TextBox1.Text) < 10000)
{
MessageBox.Show("Amount b/w 10000-20000");
TextBox1.Text = "";
return;
}


这篇关于海友们,我有一个关于限制条件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆