TextBoxBase.EndChange 方法

定义

结束更改块。

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

示例

以下示例演示如何使用 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

适用于

另请参阅