Add clickable hyperlinks to a RichTextBox without new paragraph

后端 未结 4 773
情深已故
情深已故 2020-12-06 15:49

Is it possible to dynamically add hyperlinks without creating new paragraphs like in this question Dynamically adding hyperlinks to a RichTextBox?

I want something

4条回答
  •  再見小時候
    2020-12-06 16:03

    As for making a RichTextBox or TextBox read only

    TextBoxBase.IsReadOnly Property

    For adding text you can use a run

        FlowDocument doc = new FlowDocument();
        rtb.Document = doc;
        rtb.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");
        para.Inlines.Add(link);
        Run run = new Run();
        run.Text = " next words";
        para.Inlines.Add(run);
    

提交回复
热议问题