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

适用于

另请参阅