I am in need of detecting urls in text and converting them to hyperlinks. Our clients would like this feature. I have been trying to get this to work with the control but I am unable to. I am using a regular expression to detect the URL in text. The only time it creates a hyperlink is when it is 'TreatValueAs = URL'. I pasted a dummy program
Properties
TreatValueAs = Auto ---> ?? Havent figured out how this works and in what way it works.
You may have to format the text so as to remove anything that the UltraFormattedTextEditor might interpret as a control code, but it does handle the HTML anchor tag (<a>) without any additional formatting required on your part.
Example:
this.formattedTextEditor.Value = new ParsedFormattedTextValue("This is a <a href=\"www.infragistics.com\">hyperlink</a>. This, on the other hand is not.");
I tried what you recommended. However once it finds a link I am unable to use the space bar to enter some more text. It locks the cursor when I assign the value to the editor.
test test https://www.test.com
---> Once it recognizes the "https://www.test.com" it wont allow me to enter a space to enter more text.
Sorry, I'm having a little trouble understanding how you're going about this. Please attach a sample application or a code snippet that enables me to reproduce the problem and I'll dive a little deeper.
Here is a snippet of code that I am using. This is where I am trying to parse the text and detect the URLs. However I am running into the problem I stated in a previous message.
private void utxtText_TextChanged(object sender, EventArgs e)
{
Regex regx = new Regex(@"http(s)?://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?", RegexOptions.IgnoreCase);
ParsedFormattedTextValue test = new ParsedFormattedTextValue("");
Match match = regx.Match(utxtText.Text);
link1.Clear();
link1.AppendLine(utxtText.Text);
if (match.Length > 0)
string temp = string.Format("<a href=\"{0}\">{1}</a>", match.Value, match.Value);
link1.Replace(match.Value, string.Format("<a href=\"{0}\">{1}</a>", match.Value, match.Value));
try
test = new ParsedFormattedTextValue(link1.ToString());
}
catch { }
this.utxtText.TextChanged -= new System.EventHandler(this.utxtText_TextChanged);
utxtText.Value = test.ToString();
//utxtText.Value = test;
this.utxtText.TextChanged += new System.EventHandler(this.utxtText_TextChanged);
I'm not certain about this but I think your regex pattern might be swallowing up all whitespace that follows the URL, thus removing a space character as soon as the user types it.
please let us know if you need any more help with this.