TextBoxBase.BeginChange TextBoxBase.BeginChange TextBoxBase.BeginChange TextBoxBase.BeginChange Method

定义

开始更改块。Begins a change block.

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

示例

下面的示例演示如何使用BeginChangeEndChange方法来创建更改块。The following example shows how to use the BeginChange and EndChange methods to create a change block.

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来完成更改块, 否则将会引发异常。When you call BeginChange, you must also call EndChange to complete the change block otherwise an exception will be thrown.

更改块以逻辑方式将多个更改组合到一个撤消单元中, 并阻止在更改块后引发文本内容或选择更改事件。A change block logically groups multiple changes into a single undo unit and prevents text content or selection change events from being raised until after the change block. 这样, 便可以对文本元素进行多次编辑, 而不会因另一个侦听器同时更改文本元素的风险。This way you can make multiple edits to the text element without the danger of the text element being changed at the same time by another listener. 更改块是通过调用DeclareChangeBlock方法创建的。A change block is created by calling the DeclareChangeBlock method. 调用方法会导致所有后续更改都包含在指定的更改块中, 直到对EndChange方法进行了相应调用。 BeginChangeCalling the BeginChange method causes all subsequent changes to be included in the specified change block until a corresponding call to the EndChange method is made.

适用于

另请参阅