动态地添加超链接一个RichTextBox [英] Dynamically adding hyperlinks to a RichTextBox

查看:153
本文介绍了动态地添加超链接一个RichTextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一些动态链接添加到使用WPF和C#一个RichTextBox但我没有很大的成功。我的代码是总结如下:

I'm trying to dynamically add some hyperlinks to a RichTextBox using WPF and C# but am not having much success. My code is summarised below:

FlowDocument doc = new FlowDocument();
richTextBox1.Document = doc;
richTextBox1.IsReadOnly = true;

Paragraph para = new Paragraph();
doc.Blocks.Add(para);

Hyperlink link = new Hyperlink();
link.IsEnabled = true;
link.Inlines.Add("Hyperlink");
link.NavigateUri = new Uri("http://www.google.co.uk");
link.Click += new RoutedEventHandler(this.link_Click);
para.Inlines.Add(link);

....

protected void link_Click(object sender, RoutedEventArgs e) {
    MessageBox.Show("Clicked link!");
}

当我运行这个RichTextBox中显示链接,但它是灰色的,我不能点击它?可有人请指出,我可能会错。

When I run this the RichTextBox show the link but it is grey and I cannot click on it? Can someone please point out where I might be going wrong.

感谢。

推荐答案

文件的RichTextBox 默认情况下禁用,设置 RichtTextBox.IsDocumentEnabled 真正

The Document in a RichTextBox is disabled by default, set RichtTextBox.IsDocumentEnabled to true.

这篇关于动态地添加超链接一个RichTextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆