RichTextBox.DetectUrls 属性

定义

获取或设置一个值,通过该值指示当在控件中键入某个统一资源定位器 (URL) 时,RichTextBox 是否自动设置 URL 的格式。Gets or sets a value indicating whether or not the RichTextBox will automatically format a Uniform Resource Locator (URL) when it is typed into the control.

public:
 property bool DetectUrls { bool get(); void set(bool value); };
public bool DetectUrls { get; set; }
member this.DetectUrls : bool with get, set
Public Property DetectUrls As Boolean

属性值

如果 RichTextBox 将键入到控件中的 URL 自动设置为链接格式,则为 true;否则为 falsetrue if the RichTextBox will automatically format URLs that are typed into the control as a link; otherwise, false. 默认值为 trueThe default is true.

示例

下面的代码示例包含 LinkClicked 事件的事件处理程序。The following code example contains an event handler for the LinkClicked event. 事件处理程序将处理 RichTextBox 控件文档内的链接单击,并启动默认浏览器的实例(使用 Process.Start 方法),并显示已单击的链接的页面。The event handler processes link clicks within the document of a RichTextBox control and launches an instance of the default browser (using the Process.Start method), displaying the page for the link that was clicked. 此示例要求事件处理程序已连接到 RichTextBoxLinkClicked 事件。This example requires that the event handler has been connected to the LinkClicked event for a RichTextBox.

private:
   void Link_Clicked( Object^ sender, System::Windows::Forms::LinkClickedEventArgs^ e )
   {
      System::Diagnostics::Process::Start( e->LinkText );
   }
private void Link_Clicked (object sender, System.Windows.Forms.LinkClickedEventArgs e)
{
   System.Diagnostics.Process.Start(e.LinkText);
}
Private Sub Link_Clicked(sender As Object, e As System.Windows.Forms.LinkClickedEventArgs)
   System.Diagnostics.Process.Start(e.LinkText)
End Sub

注解

如果将此属性设置为 true,则输入到由 RichTextBox 确定为 URL 的控件中的任何文本都将自动设置为链接的格式。If this property is set to true, any text entered into the control that is determined by the RichTextBox to be a URL is automatically formatted as a link. 可以为 LinkClicked 事件创建事件处理程序,以处理控件中单击的所有链接。You can create an event handler for the LinkClicked event to handle all links clicked in the control. LinkClicked 事件的事件处理程序提供的 LinkClickedEventArgs 提供的数据使您能够确定在控件中单击了哪个链接来处理链接。The LinkClickedEventArgs that is provided to the event handler for the LinkClicked event provides data that enables you to determine which link was clicked in the control in order to process the link.

适用于

另请参阅