简体   繁体   English

检查蒙面文本框是否为空或不是VB.NET

[英]Check Masked Text Box is empty or not VB.NET

I have Masked Text Boxes in my form. 我的表格中有蒙面文本框。 One is for salary, PF&ESI and Other is for Phone Number. 一个是薪水,PF&ESI和其他是电话号码。 I try to check the Masked Text Box is empty or not with following code. 我尝试使用以下代码检查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 

Only my salary, PF&ESI Masked Text Box show in Red color, But Phone number Masked Text Box is not show Red. 只有我的工资,PF&ESI蒙面文本框显示为红色,但电话号码蒙面文本框不显示红色。

I think you have the following situation: (Probably defined by the property designer) 我认为您有以下情况:(可能由物业设计师定义)

 maskedTextBoxPhoneNumber.Mask = "000000 00000"  'Or something similar'
 maskedTextBoxPhoneNumber.TextMaskFormat = MaskFormat.IncludeLiterals 

in this case your test for 在这种情况下你的测试

 if mtxt.Text = "" then 

will fail because the literals included in the mask property are returned in the property Text 将失败,因为mask属性中包含的文字在属性Text中返回

you should change the property TextMaskFormat to 你应该将属性TextMaskFormat更改为

 maskedTextBoxPhoneNumber.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals

See MSDN for MaskFormat Enumeration 有关MaskFormat枚举的信息,请参阅MSDN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM