ComboBox.EndUpdate 方法

定義

ComboBox 方法暫停繪製之後,繼續繪製 BeginUpdate() 控制項。Resumes painting the ComboBox control after painting is suspended by the BeginUpdate() method.

public:
 void EndUpdate();
public void EndUpdate ();
member this.EndUpdate : unit -> unit
Public Sub EndUpdate ()

範例

下列程式碼範例顯示 BeginUpdateEndUpdate 方法的用法。The following code example shows the usage of the BeginUpdate and EndUpdate methods. 此範例是 ComboBox 類別總覽中程式碼範例的一部分。The example is part of a code example in the ComboBox class overview.

void addGrandButton_Click( Object^ sender, System::EventArgs^ e )
{
   comboBox1->BeginUpdate();
   for ( int i = 0; i < 1000; i++ )
   {
      comboBox1->Items->Add( "New Item " + i.ToString() );
   }
   comboBox1->EndUpdate();
}
private void addGrandButton_Click(object sender, System.EventArgs e) {
    comboBox1.BeginUpdate();
    for (int i = 0; i < 1000; i++) {
        comboBox1.Items.Add("New Item " + i.ToString());
    }
    comboBox1.EndUpdate();
}
Private Sub addGrandButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    comboBox1.BeginUpdate()
    Dim I As Integer
    For I = 0 To 1000
        comboBox1.Items.Add("New Item " + i.ToString())
    Next
    comboBox1.EndUpdate()
End Sub

備註

將專案加入至 ComboBox 的慣用方法是使用 ComboBox.ObjectCollection 類別的 AddRange 方法(透過 ComboBoxItems 屬性)。The preferred way to add items to the ComboBox is to use the AddRange method of the ComboBox.ObjectCollection class (through the Items property of the ComboBox). 這可讓您一次將一個專案陣列加入清單中。This enables you to add an array of items to the list at one time. 不過,如果您想要使用 ComboBox.ObjectCollection 類別的 Add 方法一次加入一個專案,您可以使用 BeginUpdate 方法,避免每次將專案新增至清單時,控制項重新繪製 ComboBoxHowever, if you want to add items one at a time using the Add method of the ComboBox.ObjectCollection class, you can use the BeginUpdate method to prevent the control from repainting the ComboBox each time an item is added to the list. 完成將專案新增至清單的工作之後,請呼叫 EndUpdate 方法,讓 ComboBox 重新繪製。Once you have completed the task of adding items to the list, call the EndUpdate method to enable the ComboBox to repaint. 這種新增專案的方式,可能會在將大量專案新增至清單時,防止 flickered 繪製 ComboBoxThis way of adding items can prevent flickered drawing of the ComboBox when a large number of items are being added to the list.

適用於