如何检查文本框是否包含零并在C#中单击“确定”按钮时显示警告消息 [英] How to check whether textbox contains zero and display an alert message on click of ok button in C#

查看:105
本文介绍了如何检查文本框是否包含零并在C#中单击“确定”按钮时显示警告消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个接受小时的文本框。最大长度为4.只有数字和十进制值可以在文本框中输入,因此当用户输入值



0

00

000

0000

0.

00.

000.

0.0

00.0



点击确定按钮时应显示警告。



之前我正在使用这个条件

if(plannedHours ==0)

{



//显示警告信息。

}



但现在允许用户输入小数值此外,当用户点击确定按钮时,上述带有或不带小数点的零组合不会显示警告信息。



所以如何给出一个条件以便它满足所有可能的零和有和没有小数的组合吗?





请给我一个C#的解决方案。

解决方案

试试这个代码

  if (Convert.ToDouble(plannedHours)==  0 
{

// 显示提醒信息。
}


Hi,

i have a textbox which accepts hours. The max length is 4. Only numeric and decimal values can be entered in the textbox so when the user enters values like

0
00
000
0000
0.
00.
000.
0.0
00.0

on click of ok button an alert should be displayed.

previously i was using this condition
if(plannedHours == "0")
{

// display an alert message.
}

But now since the user is allowed to enter decimal values also, the above combinations of zero's with or without decimal points is not displaying an alert message when user clicks on ok button.

so how can i give a condition so that it satisfies all the possible combinations of zero's with and without decimal also?


please provide me a solution in C#.

解决方案

Try this code

if(Convert.ToDouble(plannedHours) == 0)
{

// display an alert message.
}


这篇关于如何检查文本框是否包含零并在C#中单击“确定”按钮时显示警告消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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