[英]VSTO Add-in C# Adding Clickable Hyperlinks to Text in Task Pane
在下图中,我在 Microsoft Excel 中有一个任务窗格,其中包含一个富文本框 (RTB)。 在这个文本框中,我想将一些文本变成可点击的超链接。 现在,我知道如果您将超链接放入 RTB,您可以使用“Process.Start(e.LinkText);”之类的内容使其可点击。 正如我之前的一个问题所回答的那样。 但是我不确定如何将链接嵌入到文本中,以便用户实际上看不到超链接。 例如,我希望下图中的“google”在用户点击它时将用户带到www.google.com 。 有关如何完成此操作的任何提示?
当前代码仅将一些文本放入 RTB:
string test_string = "Google";
//Used to set the text in the task pane in real time
foreach (Control rtbControl in GlobalVars.myUserControl1.Controls)
{
if (rtbControl is RichTextBox & rtbControl.Name == "documentResults")
{
rtbControl.Text = test_string;
}
}
对于RichTextBox
,您需要使用适当的 RTF 标记,您可以在其中指定 colors。
string RTFText =
'{\rtf1 ' +
'{\colortbl ;\red238\green0\blue0;}' +
'Lorem ipsum dolor sit amet ' +
'{\b {\field{\*\fldinst{HYPERLINK "https://www.example.com/" }}' +
'{\fldrslt{\cf1 CLICK_HERE\cf0 }}}} ' +
'consectetur adipiscing elit.}';
您可能会发现超链接的 RTF 语法是什么? 和Inno Setup - 如何更改 RTF 文本中超链接的颜色? 页面有帮助。
如果您使用单独的控件,您可以设置LinkLabel颜色相关的属性,使其看起来像您的屏幕截图:
// Set the color of the links to black, unless the mouse
// is hovering over a link.
linkLabel1.LinkColor = System.Drawing.Color.Black;
linkLabel1.ActiveLinkColor = System.Drawing.Color.Blue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.