ListBox.EndUpdate 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在繪畫暫停BeginUpdate()後,繼續繼續繪畫ListBox控制。
public:
void EndUpdate();
public void EndUpdate();
member this.EndUpdate : unit -> unit
Public Sub EndUpdate ()
範例
以下程式碼範例使用 和 EndUpdate 方法BeginUpdate,並在 中加入五千個項目。ListBox 此範例要求一個 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 首選方式是使用 AddRange 類別的方法 ListBox.ObjectCollection (透過 Items 的 ListBox屬性)。 這讓你可以一次在清單中新增多個項目。 不過,如果你想用 Add 類別的方法 ListBox.ObjectCollection 一個一個新增項目,可以用這個 BeginUpdate 方法防止每次新增項目時控制項重新繪製 ListBox 。 完成將項目加入清單的任務後,呼叫 EndUpdate 該方法來啟用 ListBox 重新繪製。 這種新增項目的方式可以避免在大量項目加入列表中時出現閃爍繪製 ListBox 的情況。