ListBox.EndUpdate 方法

定義

ListBox 方法暫停繪製之後,繼續繪製 BeginUpdate() 控制項。

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

範例

下列程式碼範例會在將五千個專案新增至 ListBox 時使用 BeginUpdateEndUpdate 方法。 這個範例要求 ListBox 已將名為 listBox1 的控制項新增至 , Form 而且這個方法會放在表單中,並從中呼叫。

void AddToMyListBox()
{
   // Stop the ListBox from drawing while items are added.
   listBox1->BeginUpdate();

   // Loop through and add five thousand new items.
   for ( int x = 1; x < 5000; x++ )
   {
      listBox1->Items->Add( String::Format( "Item {0}", x ) );
   }
   listBox1->EndUpdate();
}
public void AddToMyListBox()
{
   // Stop the ListBox from drawing while items are added.
   listBox1.BeginUpdate();

   // Loop through and add five thousand new items.
   for(int x = 1; x < 5000; x++)
   {
      listBox1.Items.Add("Item " + x.ToString());   
   }
   // End the update process and force a repaint of the ListBox.
   listBox1.EndUpdate();
}
Public Sub AddToMyListBox()
    ' Stop the ListBox from drawing while items are added.
    listBox1.BeginUpdate()
       
    ' Loop through and add five thousand new items.
    Dim x As Integer
    For x = 1 To 4999
        listBox1.Items.Add("Item " & x.ToString())
    Next x
    ' End the update process and force a repaint of the ListBox.
    listBox1.EndUpdate()
End Sub

備註

將專案新增至 ListBox 的慣用方式是透過) 的 ListBox.ObjectCollection ListBox 屬性,使用 AddRange 類別 Items 的 方法 (。 這可讓您一次將專案陣列新增至清單。 不過,如果您想要使用 Add 類別的 ListBox.ObjectCollection 方法一次新增一個專案,您可以使用 BeginUpdate 方法防止控制項在每次將專案加入清單時重新繪製 ListBox 。 完成將專案新增至清單的工作之後,請呼叫 EndUpdate 方法來啟用 ListBox 重新繪製。 這樣一來,新增專案可能會防止 ListBox 在大量專案新增至清單時閃爍繪製 。

適用於

另請參閱