RichTextBox.Protected RichTextBox.Protected RichTextBox.Protected RichTextBox.Protected Event

定义

当用户尝试修改控件中受保护的文本时发生。Occurs when the user attempts to modify protected text in the control.

public:
 event EventHandler ^ Protected;
public event EventHandler Protected;
member this.Protected : EventHandler 
Public Custom Event Protected As EventHandler 

示例

下面的代码示例演示如何使用此成员。The following code example demonstrates the use of this member. 在此示例中, 事件处理程序报告Protected事件的发生。In the example, an event handler reports on the occurrence of the Protected event. 此报表可帮助你了解何时发生事件, 并可帮助你进行调试。This report helps you to learn when the event occurs and can assist you in debugging. 若要报告多个事件或频繁发生的事件, 请考虑MessageBox.ShowConsole.WriteLine消息替换为多行或将TextBox其追加到多行。To report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

若要运行示例代码, 请将其粘贴到包含名为RichTextBox RichTextBox1的类型的实例的项目中。To run the example code, paste it into a project that contains an instance of type RichTextBox named RichTextBox1. 然后, 确保事件处理程序与Protected事件相关联。Then ensure that the event handler is associated with the Protected event.

private void RichTextBox1_Protected(Object sender, EventArgs e) {

   MessageBox.Show("You are in the RichTextBox.Protected event.");

}
Private Sub RichTextBox1_Protected(sender as Object, e as EventArgs) _ 
     Handles RichTextBox1.Protected

   MessageBox.Show("You are in the RichTextBox.Protected event.")

End Sub

注解

您可以在应用程序中为此事件创建事件处理程序,以确定用户是否试图修改控件中已标记为受保护的文本。You can create an event handler for this event in your applications to determine when the user has attempted to modify text that has been marked as protected in the control. 事件处理程序可用于通知用户,用户试图修改的文本是受保护的,或者显示一个对话框,使用户能够对文本进行适当的更改。The event handler can be used to notify the user that the text the user is attempting to modify is protected or to display a dialog box that enables the user to make appropriate changes to the text. 例如,如果受保护的区域是日期,则可以显示一个对话框,用户可以通过该对话框选择可应用于控件文本的日期。For example, if the protected area is a date, you can display a dialog box that enables the user to choose a date which can then be applied to the text of the control.

有关如何处理事件的详细信息,请参阅处理和引发事件For more information about how to handle events, see Handling and Raising Events.

适用于