RichTextEditBox and LinkLabel winforms c#

393 Views Asked by At

I am using a windows forms RichTextEditBox. I load a RTF file into the control. I then set the following code.

 int indexToText = rteb.Find("here");

 LinkLabel link = new LinkLabel();
 link.Text = "here";
 link.LinkBehavior = LinkBehavior.AlwaysUnderline;
 link.LinkClicked += new 
     LinkLabelLinkClickedEventHandler(this.link_LinkClicked);

 LinkLabel.Link data = new LinkLabel.Link();
 data.LinkData = "Sending Report Results to Multiple Recipients.pdf";
 link.Links.Add(data);

 link.AutoSize = true;
 link.Location = rteb.GetPositionFromCharIndex(indexToText);
 link.Height = 40;
 link.Width = 60;
 link.ForeColor = Color.Blue;
 rteb.Controls.Add(link);

when the app is run, the word "here" is in blue, but I don't get an underline and when I try clicking on the word, my click event doesn't fire off. What am I missing here?

1

There are 1 best solutions below

4
Reza Aghaei On

To set an underlined link area in LinkLabel you should set LinkArea property to the range which should be shown as link, for example:

LinkLabel link = new LinkLabel();
link.Text = "here";
link.LinkArea = new LinkArea(0, link.Text.Length);
link.LinkBehavior = LinkBehavior.AlwaysUnderline;