簡體   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