We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to enable hyperlinks in EditControl?

Platform: WinForms |
Control: EditControl |
Published Date: October 23, 2015 |
Last Revised Date: May 24, 2019

You can enable hyperlinks in the EditControl by calculating the specified text positions with the following events.

  1. MouseMove
  2. MouseDown

 

MouseMove: Changes the cursor, when mouse hovers on the required text of the control.

MouseDown: Navigates the specified webpage, when mouse button is pressed on the required text of the control. The CurrentLineText property helps match the input text in the EditControl.

 

The following code example demonstrates the same.

C#

//Initializes the hyperlink text.
private string text = "http://www.google.com";
//Initializes the file path.
private string filePath = Path.GetDirectoryName(Application.ExecutablePath) + @"\..\..\hyper.php";
//Loads files in EditControl.
this.editControl1.LoadFile(filePath);
//Specifies the cursor.
private void editControl1_MouseMove(object sender, MouseEventArgs e)
{
    //Gets the mouse point.
    Point pointVirtual = editControl1.PointToVirtualPosition(new Point(e.X, e.Y));
    if (pointVirtual.Y > 0)
    {
        //Gets the line.
        ILexemLine line = editControl1.GetLine(pointVirtual.Y);
        if (line != null)
        {
            ILexem lexem = line.FindLexemByColumn(pointVirtual.X);
            if (lexem != null)
            {
                IConfigLexem configLexem = lexem.Config as IConfigLexem;
                if (text.Contains(lexem.Text))
                    this.editControl1.Cursor = Cursors.Hand;
                else
                    this.editControl1.Cursor = Cursors.Default;
            }
            else
                this.editControl1.Cursor = Cursors.Default;
        }
    }
}
//Navigates to the website.
void editControl1_MouseDown(object sender, MouseEventArgs e)
{
    if (this.editControl1.CurrentLineText.Contains(text) && text.Contains(this.editControl1.GetCurrentWord()))
    {
        //Opens the hyperlink in the webpage.
        ProcessStartInfo hyperlink = new ProcessStartInfo("http://www.google.com");
        Process.Start(hyperlink);
    }
}

 

VB

'Initializes the hyperlink text.
Private textValue As String = "http://www.google.com"
'Initializes the file path.
Private filePath As String = Path.GetDirectoryName(Application.ExecutablePath) & "\..\..\hyper.php"
'Loads files in EditControl.
Me.editControl1.LoadFile(filePath)
'Specifies the cursor.
Private Sub editControl1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
 'Gets the mouse point.
 Dim pointVirtual As Point = editControl1.PointToVirtualPosition(New Point(e.X, e.Y))
 If pointVirtual.Y > 0 Then
  'Gets the line.
  Dim line As ILexemLine = editControl1.GetLine(pointVirtual.Y)
  If line IsNot Nothing Then
   Dim lexem As ILexem = line.FindLexemByColumn(pointVirtual.X)
   If lexem IsNot Nothing Then
    Dim configLexem As IConfigLexem = TryCast(lexem.Config, IConfigLexem)
    If text.Contains(lexem.Text) Then
     Me.editControl1.Cursor = Cursors.Hand
    Else
     Me.editControl1.Cursor = Cursors.Default
    End If
   Else
    Me.editControl1.Cursor = Cursors.Default
   End If
  End If
 End If
End Sub
'Navigates to the website.
Private Sub editControl1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
     If Me.editControl1.CurrentLineText.Contains(textValue) AndAlso textValue.Contains(Me.editControl1.GetCurrentWord()) Then
         'Opens the hyperlink in the webpage.
          Dim hyperlink As New ProcessStartInfo("http://www.google.com")
          Process.Start(hyperlink)
     End If
End Sub

 

Note:

PointToVirtualPosition helps to get the virtual position of the text. It also helps to converts the points in client coordinates to the virtual position in text.

 

 

EditControl shows with hyperlinks in C#

Figure 1: EditControl shows with hyperlinks in C#

EditControl shows with hyperlinks in VB

Figure 2: EditControl shows with hyperlinks in VB

Webpage loaded to browser after clicking hyperlink

Figure 3: Webpage loaded to browser after clicking the Hyperlink in EditControl

Sample Links:

C#: EditControl_HyperLink_C#

VB: EditControl_HyperLink_VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon