繁体   English   中英

检查蒙面文本框是否为空或不是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

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

暂无
暂无

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

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