ItemCheckEventArgs.NewValue 屬性

定義

取得或設定值,指出項目的核取方塊要設定為已核取、未核取或是不定。

public:
 property System::Windows::Forms::CheckState NewValue { System::Windows::Forms::CheckState get(); void set(System::Windows::Forms::CheckState value); };
public System.Windows.Forms.CheckState NewValue { get; set; }
member this.NewValue : System.Windows.Forms.CheckState with get, set
Public Property NewValue As CheckState

屬性值

其中一個 CheckState 值。

範例

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

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

private void CheckedListBox1_ItemCheck(Object sender, ItemCheckEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "Index", e.Index );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "NewValue", e.NewValue );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "CurrentValue", e.CurrentValue );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "ItemCheck Event" );
}
Private Sub CheckedListBox1_ItemCheck(sender as Object, e as ItemCheckEventArgs) _ 
     Handles CheckedListBox1.ItemCheck

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "Index", e.Index)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "NewValue", e.NewValue)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "CurrentValue", e.CurrentValue)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"ItemCheck Event")

End Sub

備註

這個屬性可讓您在控制項變更 CheckedListBox 檢查狀態之前,判斷指定專案的新檢查狀態。 除了判斷新的檢查狀態之外,您還可以在 事件的事件處理常式 ItemCheck 中使用這個屬性,將狀態變更為與指定的檢查狀態不同的檢查狀態。 例如,如果使用者在中 CheckedListBox 決定的專案旁邊放置核取記號不應根據應用程式的狀態進行檢查,您可以將此屬性設定為先前的設定或不同的檢查狀態來覆寫核取記號狀態的變更。

適用於

另請參閱