TypeValidationEventArgs.IsValidInput 屬性

定義

取得值,指出格式化輸入字串是否成功轉換成驗證的型別。

public:
 property bool IsValidInput { bool get(); };
public bool IsValidInput { get; }
member this.IsValidInput : bool
Public ReadOnly Property IsValidInput As Boolean

屬性值

如果格式化輸入字串可以轉換成 ValidatingType 屬性所指定的型別,則為 true,否則為 false

範例

下列程式碼範例示範如何使用這個成員。 在此範例中,事件處理常式會報告事件的發生次數 MaskedTextBox.TypeValidationCompleted 。 此報告可協助您瞭解事件發生的時間,並可協助您進行偵錯。 若要報告多個事件或經常發生的事件,請考慮將 取代 MessageBox.ShowConsole.WriteLine 或將訊息附加至多行 TextBox

若要執行範例程式碼,請將它貼入包含名為 MaskedTextBox1 之類型 MaskedTextBox 實例的專案。 然後,確定事件處理常式與 事件相關聯 MaskedTextBox.TypeValidationCompleted

private void MaskedTextBox1_TypeValidationCompleted(Object sender, TypeValidationEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "Cancel", e.Cancel );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "IsValidInput", e.IsValidInput );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Message", e.Message );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "ReturnValue", e.ReturnValue );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "ValidatingType", e.ValidatingType );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "TypeValidationCompleted Event" );
}
Private Sub MaskedTextBox1_TypeValidationCompleted(sender as Object, e as TypeValidationEventArgs) _ 
     Handles MaskedTextBox1.TypeValidationCompleted

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "Cancel", e.Cancel)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "IsValidInput", e.IsValidInput)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Message", e.Message)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "ReturnValue", e.ReturnValue)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "ValidatingType", e.ValidatingType)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"TypeValidationCompleted Event")

End Sub

備註

屬性 IsValidInput 表示 在 屬性所 ValidatingType 表示的 中找到 Type 的方法成功 Parse 。 此類型必須包含 Parse 方法 () 具有下列其中一個或兩個簽章:

public static Object Parse(string)

public static Object Parse(string, IFormatProvider)

Parse會在 控制項引發 TypeValidationCompleted 事件之前 MaskedTextBox 呼叫 。 這個方法會使用 類別之 屬性 MaskedTextBox 的內容減去提示字元 Text 來叫用。 如果成功,它會傳回已轉換的物件;否則會傳 null 回 。

如需類型驗證程式的詳細資訊,請參閱 TypeValidationCompleted 事件。

適用於

另請參閱