当我将 www.stackoverflow 添加到我的 RichTextBox 并运行该程序时,它以蓝色显示并作为超链接显示,但是当我单击它时什么也没有发生.我该如何解决这个问题?
When I add www.stackoverflow into my RichTextBox and run the program it is shown in blue and as a hyperlink yet when I click it nothing happens. How can I fix this?
推荐答案确保文本属性包含有效的 url.例如.www.stackoverflow/
将 DetectUrls 属性设置为 true
为 LinkClicked 事件编写一个事件处理程序.
Write an event handler for the LinkClicked event.
就我个人而言,我不会像 Microsoft 建议的那样将 "IExplore.exe" 作为参数传递给 Process.Start 调用,因为这假定它已安装,并且是用户的首选浏览器.如果您只是将 url 传递给进程启动(如下所示),那么 Windows 将做正确的事情并使用适当的 url 启动用户的首选浏览器.
Personally, I wouldn't pass "IExplore.exe" in as a parameter to the Process.Start call as Microsoft advise as this presupposes that it is installed, and is the user's preferred browser. If you just pass the url to process start (as per below) then Windows will do the right thing and fire up the user's preferred browser with the appropriate url.
private void mRichTextBox_LinkClicked (object sender, LinkClickedEventArgs e) { System.Diagnostics.Process.Start(e.LinkText); }更多推荐
如何在 RichTextBox 中创建超链接?
发布评论