Click 事件、CommandButton 控件、加速器、Caption 属性示例Click event, CommandButton control, Accelerator, Caption properties example

本示例在用户每次使用鼠标或加速键单击按钮时, 更改**命令按钮** 的**加速** 键和**标题** 属性。This example changes the Accelerator and Caption properties of a CommandButton each time the user clicks the button by using the mouse or the accelerator key. Click事件包含更改加速键标题属性的代码。The Click event contains the code to change the Accelerator and Caption properties.

To try this example, paste the code into the Declarations section of a form containing a CommandButton named CommandButton1.To try this example, paste the code into the Declarations section of a form containing a CommandButton named CommandButton1.

Private Sub UserForm_Initialize() 
 CommandButton1.Accelerator = "C" 
 'Set Accelerator key to COMMAND + C 
End Sub 
 
Private Sub CommandButton1_Click () 
 If CommandButton1.Caption = "OK" Then 
 'Check caption, then change it. 
 CommandButton1.Caption = "Clicked" 
 CommandButton1.Accelerator = "C" 
 'Set Accelerator key to COMMAND + C 
 Else 
 CommandButton1.Caption = "OK" 
 CommandButton1.Accelerator = "O" 
 'Set Accelerator key to COMMAND + O 
 End If 
End Sub

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.