Table of contents
TOC
折叠目录
展开目录

CanUndo、CanRedo 属性、UndoAction、RedoAction 方法示例CanUndo, CanRedo Properties, UndoAction, RedoAction Methods Example

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

下面的示例演示如何撤消或重做文字编辑在文本框或ComboBox的文本区域内。本示例检查是否撤消或重做操作可能,然后执行相应的操作。此示例使用CanUndoCanRedo属性中,并在UndoActionRedoAction方法。The following example demonstrates how to undo or redo text editing within a text box or within the text area of a ComboBox. This sample checks whether an undo or redo operation can occur and then performs the appropriate action. The sample uses the CanUndo and CanRedo properties, and the UndoAction and RedoAction methods.

若要使用此示例,请复制比示例代码到窗体的声明部分。确保该窗体包含:To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • 名为 TextBox1文本框A TextBox named TextBox1.

  • 名为 ComboBox1的组合框A ComboBox named ComboBox1.

  • 两个命令按钮控件命名为 CommandButton1 和 CommandButton2。Two CommandButton controls named CommandButton1 and CommandButton2.

Private Sub CommandButton1_Click() 
 If UserForm1.CanUndo = True Then 
 UserForm1.UndoAction 
 MsgBox "Undid IT" 
 Else 
 MsgBox "No undo performed." 
 End If 
End Sub 

Private Sub CommandButton2_Click() 
 If UserForm1.CanRedo = True Then 
 UserForm1.RedoAction 
 MsgBox "Redid IT" 
 Else 
 MsgBox "No redo performed." 
 End If 
End Sub 

Private Sub UserForm_Initialize() 
 TextBox1.Text = "Type your text here." 

 ComboBox1.ColumnCount = 3 
 ComboBox1.AddItem "Choice 1, column 1" 
 ComboBox1.List(0, 1) = "Choice 1, column 2" 
 ComboBox1.List(0, 2) = "Choice 1, column 3" 

 CommandButton1.Caption = "Undo" 
 CommandButton2.Caption = "Redo" 
End Sub
© 2018 Microsoft