共用方式為


TextBoxBase.BeginChange 方法

定義

開始變更區塊。

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

範例

下列範例示範如何使用 BeginChangeEndChange 方法來建立變更區塊。

TextBox myTextBox = new TextBox();

// Begin the change block. Once BeginChange() is called
// no text content or selection change events will be raised 
// until EndChange is called. Also, all edits made within
// a BeginChange/EndChange block are wraped in a single undo block.
myTextBox.BeginChange();

// Put some initial text in the TextBox.
myTextBox.Text = "Initial text in TextBox";

// Make other changes if desired...

// Whenever BeginChange() is called EndChange() must also be
// called to end the change block.
myTextBox.EndChange();
Dim myTextBox As New TextBox()

' Begin the change block. Once BeginChange() is called
' no text content or selection change events will be raised 
' until EndChange is called. Also, all edits made within
' a BeginChange/EndChange block are wraped in a single undo block.
myTextBox.BeginChange()

' Put some initial text in the TextBox.
myTextBox.Text = "Initial text in TextBox"

' Make other changes if desired...

' Whenever BeginChange() is called EndChange() must also be
' called to end the change block.
myTextBox.EndChange()

備註

注意

當您呼叫 BeginChange 時,也必須呼叫 EndChange 來完成變更區塊,否則會擲回例外狀況。

變更區塊會以邏輯方式將多個變更分組成單一復原單位,並防止在變更區塊之後引發文字內容或選取範圍變更事件。 如此一來,您就可以對文字元素進行多個編輯,而不會讓另一個接聽程式同時變更文字元素的危險。 變更區塊是藉由呼叫 DeclareChangeBlock 方法來建立。 BeginChange呼叫 方法會導致指定的變更區塊中包含所有後續變更,直到對 方法的對應呼叫 EndChange 完成為止。

適用於

另請參閱