rtftextbox 和文档内的超链接/锚点

发布于 2024-07-09 23:36:27 字数 604 浏览 4 评论 0原文

几个小时前,我发现使用标准 .net 2.0 winforms 控件(RichTextBox)显示 *.rtf 文档非常容易。 它甚至可以显示图片,这真的很酷,但对我来说,缺少一个功能 - 超链接。 我准备了 *.rtf 文档,其中包含一些指向文档内段落的超链接。 然后我将此文件放入资源中并加载到控件的 rtf 属性中,但不幸的是,单击链接不起作用。 是否有可能的黑客或解决方法来启用超链接?

编辑:

我的客户将准备一份简短的文档(假设一份 *.docx 文件或一份 *.html 文件)。

它将包含几个章节,我们希望将小目录放在文档的顶部。

预期的行为是用户单击主题,控件将其内容滚动到文档中的所需位置。

所以也许这不是关于链接而是关于书签。


好的,我将尝试描述所需解决方案的大部分。

我的客户将准备一份简短的文档(假设一份 *.docx 文件或一份 *.html 文件)。

它将包含几个章节,我们希望将小目录放在文档的顶部。

预期的行为是用户单击主题,控件将其内容滚动到文档中的所需位置。

所以也许这不是关于链接而是关于书签。

A few hours ago I found that it's really easy to display *.rtf document using standart .net 2.0 winforms control (RichTextBox). It's really cool that it can display even pictures, but for me there's one missing feature - hyperlinking.
I prepared *.rtf document with a few hyperlinks to paragraphs inside document. Then I put this file into resources and loaded to rtf property of control but unluckly, clicking on links doesn't work.
Is there possible a hack or workaround to enable hyperlinks?

EDIT:

My customer will prepare one short document (let's say one *.docx file or one *.html file).

It will contain a few chapters and we want to place small table of contents at the top of document.

The expected behaviour is that user click topic and the control scroll its content to desired place in document.

So maybe it's not about links but about bookmarking.


OK, I'll try to describe larger part of needed solution.

My customer will prepare one short document (let's say one *.docx file or one *.html file).

It will contain a few chapters and we want to place small table of contents at the top of document.

The expected behaviour is that user click topic and the control scroll its content to desired place in document.

So maybe it's not about links but about bookmarking.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坠似风落 2024-07-16 23:36:27

您的链接格式如何?DetectUrl 是否正确?

来自代码项目 -> 仅以一种已识别协议(http:、file:、mailto:、ftp:、https:、gopher:、nntp:、prospero:、telnet:、news:、wais:、outlook:)开头的链接会被识别并重新格式化。

http://www.codeproject.com/KB/edit/RichTextBoxLinks.aspx

http:// msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.detecturls(VS.80).aspx

Microsoft 文章提供了有关 LinkClicked 事件的示例。

private void Link_Clicked (object sender, System.Windows.Forms.LinkClickedEventArgs e)
{
   System.Diagnostics.Process.Start(e.LinkText);
}

How are your links formatted and is DetectUrl true?

From codeproject -> only links starting with one of the recognized protocols (http:, file:, mailto:, ftp:, https:, gopher:, nntp:, prospero:, telnet:, news:, wais:, outlook:) are recognized and reformatted.

http://www.codeproject.com/KB/edit/RichTextBoxLinks.aspx

http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.detecturls(VS.80).aspx

The microsoft article has an example on the LinkClicked event.

private void Link_Clicked (object sender, System.Windows.Forms.LinkClickedEventArgs e)
{
   System.Diagnostics.Process.Start(e.LinkText);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文