如何验证Textbox.text是不是空的? [英] how to validate the Textbox.text is not empty?

查看:75
本文介绍了如何验证Textbox.text是不是空的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人会告诉我一个方便的方法来验证文本框的值在Winform中不为null或为空。

if-else条件仅适用于winform或解决方案中较少的文本框,

if(Textbox1.text == null)

{

...

}

其他

{

...

}


但如果有很多of textbox?

would somebody show me a convenient way to validate Textbox''s value are not null or empty in Winform.
if-else condition is only good for fewer textboxs in a winform or solution,
if(Textbox1.text==null)
{
...
}
else
{
...
}

but if there are lots of textbox?

推荐答案

这个代码可以帮助你..

将文本框值转换成字符串

if(textbox1.text =="")
may this code would help you..
after converting textbox value into string
if(textbox1.text=="")


如果winform中有六个文本形式

我认为这不是一个好方法写一下

if((Textbox1.text =="")&&(Textbox1.text == null))





if((Textbox2.text =="")&&(Textbox2.text == null))





if((Textbox3.text =="&qu ot;)&&(Textbox3.text == null))





if((Textbox4.text == "")&&(Textbox4.text == null))









@ mohit2k8
if there are six textforms in a winform
I think it''s not a good way to write
if((Textbox1.text=="")&&(Textbox1.text==null))
.
.
if((Textbox2.text=="")&&(Textbox2.text==null))
.
.
if((Textbox3.text=="")&&(Textbox3.text==null))
.
.
if((Textbox4.text=="")&&(Textbox4.text==null))
.
.
.
.

@mohit2k8


你有很多选择,IMO,最糟糕的是创建一个辅助方法,这在文本组件列表中,更好的是学习装饰器模式: http:/ /en.wikipedia.org/wiki/Decorator_pattern

您可以装饰文本框以验证其文本。如果你想编写可维护的gui程序,你将需要学习这种模式。
You have many options, IMO, worst is to create a helper method that does this on a list of text components, much better is to learn the decorator pattern:http://en.wikipedia.org/wiki/Decorator_pattern
You decorate the text boxes with ability to validate their text. You are going to need to learn to learn this pattern if you want to write maintainable gui programs anyway.


这篇关于如何验证Textbox.text是不是空的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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