1

I have been able to get links appearing in my RichTextbox. The first entry is correct but when I try appending a new line that also contains a link, the first entry is in the same position as the new link. When clicking on the link it retains it's first entries hyperlink.

enter image description here

I want each line to have it's own hyperlink (where it's underlined)

Code used to append a Link

public void AppendLink(string text, string linkText)
{
    LinkLabel link = new LinkLabel();
    link.Text = text;
    link.LinkClicked += new LinkLabelLinkClickedEventHandler(this.link_LinkClicked);
    LinkLabel.Link data = new LinkLabel.Link();
    data.LinkData = linkText;
    link.Links.Add(data);

    link.Location = this.logTextBox.GetPositionFromCharIndex(this.logTextBox.TextLength);
    this.logTextBox.Controls.Add(link);

    logTextBox.SelectionFont = UNDERLINE_FONT;
    this.logTextBox.AppendText(s);
}

Called using this

AppendLogLine("Sealed ");
AppendLink(itemName, GetItemLink(itemName));
AppendLog(" is an unknown item. Keeping."); 

Append Log and AppendLogLine does the same as AppendLink just doesn't create a link and uses a different Font

JamesVeug
  • 240
  • 2
  • 10
  • 1
    _this.logTextBox.Controls.Add(link);_ That is not how you should do it! Look [here](https://stackoverflow.com/questions/435607/how-can-i-make-a-hyperlink-work-in-a-richtextbox) – TaW Feb 28 '20 at 19:27
  • Or have a look [here](https://stackoverflow.com/questions/29606198/clickable-text-in-richtextbox/29608548?r=SearchResults&s=2|50.1296#29608548) – TaW Feb 28 '20 at 20:48

0 Answers0