共用方式為


MaskedTextBox.MaskFull 屬性

定義

取得值,指出所有必要和選擇性的輸入是否已經輸入到輸入遮罩中。

public:
 property bool MaskFull { bool get(); };
[System.ComponentModel.Browsable(false)]
public bool MaskFull { get; }
[<System.ComponentModel.Browsable(false)>]
member this.MaskFull : bool
Public ReadOnly Property MaskFull As Boolean

屬性值

如果已經輸入所有必要和選擇性的輸入,則為 true,否則為 false

屬性

範例

下列程式碼範例會處理 MaskInputRejected 事件,並在使用遮罩中的所有位置之後嘗試輸入資料時,使用 ToolTip 來警示使用者。

private void Form1_Load(object sender, EventArgs e)
{
    maskedTextBox1.Mask = "00/00/0000";

    maskedTextBox1.MaskInputRejected += new MaskInputRejectedEventHandler(maskedTextBox1_MaskInputRejected);
    maskedTextBox1.KeyDown += new KeyEventHandler(maskedTextBox1_KeyDown);
}

void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
{
    if (maskedTextBox1.MaskFull)
    {
        toolTip1.ToolTipTitle = "Input Rejected - Too Much Data";
        toolTip1.Show("You cannot enter any more data into the date field. Delete some characters in order to insert more data.", maskedTextBox1, 0, -20, 5000);
    }
    else if (e.Position == maskedTextBox1.Mask.Length)
    {
        toolTip1.ToolTipTitle = "Input Rejected - End of Field";
        toolTip1.Show("You cannot add extra characters to the end of this date field.", maskedTextBox1, 0, -20, 5000);
    }
    else
    {
        toolTip1.ToolTipTitle = "Input Rejected";
        toolTip1.Show("You can only add numeric characters (0-9) into this date field.", maskedTextBox1, 0, -20, 5000);
    }
}

void maskedTextBox1_KeyDown(object sender, KeyEventArgs e)
{
    // The balloon tip is visible for five seconds; if the user types any data before it disappears, collapse it ourselves.
    toolTip1.Hide(maskedTextBox1);
}
Private Sub MaskedTextBox1_MaskInputRejected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MaskInputRejectedEventArgs) Handles MaskedTextBox1.MaskInputRejected
    If (Me.MaskedTextBox1.MaskFull) Then
        ToolTip1.ToolTipTitle = "Input Rejected - Too Much Data"
        ToolTip1.Show("You cannot enter any more data into the date field. Delete some characters in order to insert more data.", Me.MaskedTextBox1, Me.MaskedTextBox1.Location.X, Me.MaskedTextBox1.Location.Y, 5000)
    ElseIf (e.Position = Me.MaskedTextBox1.Mask.Length) Then
        ToolTip1.ToolTipTitle = "Input Rejected - End of Field"
        ToolTip1.Show("You cannot add extra characters to the end of this date field.", Me.MaskedTextBox1, 0, -20, 5000)
    Else
        ToolTip1.ToolTipTitle = "Input Rejected"
        ToolTip1.Show("You can only add numeric characters (0-9) into this date field.", Me.MaskedTextBox1, 0, -20, 5000)
    End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.ToolTip1.IsBalloon = True
    Me.MaskedTextBox1.Mask = "00/00/0000"
End Sub

Private Sub MaskedTextBox1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MaskedTextBox1.KeyDown
    ' The balloon tip is visible for five seconds; if the user types any data before it disappears, collapse it ourselves.
    Me.ToolTip1.Hide(Me.MaskedTextBox1)
End Sub

備註

您可以使用 MaskFull 事件處理常式內的 MaskInputRejected 屬性來判斷使用者的輸入是否遭到拒絕,因為遮罩中沒有剩餘的輸入。 若要判斷是否只輸入必要的輸入元素,請使用 MaskCompleted 屬性。

適用於

另請參閱