简体   繁体   English

从C#Richtextbox中的数据库加载后处理超链接Click事件

[英]Handle Hyperlink Click event after load from Database in C# Richtextbox

I add document of Richtextbox to database. 我将Richtextbox的文档添加到数据库中。 Document have several hyperlink. 文件有几个超链接。 Every hyperlink added to this richtextbox by programmatically as follows: 每个超链接通过编程方式添加到该Richtextbox中,如下所示:

        RichTextBox.IsDocumentEnabled = true;
        RichTextBox.IsReadOnly = true;
        Run run = new Run(RichTextBox.Selection.Text);
        Hyperlink hyp = new Hyperlink(run);
        WordMain main = new WordMain();
        hyp.Click += new RoutedEventHandler(main.hyperLink_Click);
        hyp.NavigateUri = new Uri("http://search.msn.com");
        RichTextBox.Cut();

        var container = new InlineUIContainer(new TextBlock(hyp), RichTextBox.Selection.Start);
        RichTextBox.IsDocumentEnabled = true;
        RichTextBox.IsReadOnly = false;

After loading data from database I can't handle click event in a new Richtextbox. 从数据库加载数据后,我无法处理新RichTextbox中的click事件。 Please, help. 请帮忙。

So I find solution. 所以我找到了解决方案。 I only add codes as follow to richtextbox 我只将代码如下添加到richtextbox

        <RichTextBox.Resources>
            <Style TargetType="Hyperlink">
                <Setter Property="Cursor" Value="Hand" />
                <EventSetter Event="Click" Handler="hyperLink_Click" />
            </Style>
        </RichTextBox.Resources>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM