![](/img/trans.png)
[英]How to make conditions when inserting empty data in masked text box in vb.net
[英]Check Masked Text Box is empty or not VB.NET
我的表格中有蒙面文本框。 一个是薪水,PF&ESI和其他是电话号码。 我尝试使用以下代码检查Masked Text Box是否为空。
Dim mtxt As Control
Dim flag3 As Boolean
flag3 = False
For Each mtxt In EMPGBDATA.Controls
If TypeOf mtxt Is MaskedTextBox Then
If mtxt.Text = "" Then
mtxt.BackColor = Color.Red
flag3 = True
End If
End If
Next
只有我的工资,PF&ESI蒙面文本框显示为红色,但电话号码蒙面文本框不显示红色。
我认为您有以下情况:(可能由物业设计师定义)
maskedTextBoxPhoneNumber.Mask = "000000 00000" 'Or something similar'
maskedTextBoxPhoneNumber.TextMaskFormat = MaskFormat.IncludeLiterals
在这种情况下你的测试
if mtxt.Text = "" then
将失败,因为mask属性中包含的文字在属性Text
中返回
你应该将属性TextMaskFormat
更改为
maskedTextBoxPhoneNumber.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.