Imports System.Text.RegularExpressions

Public Class WikiLinkLabel
    Inherits LinkLabel

    Public Overrides Property Text() As String
        Get
            Return MyBase.Text
        End Get
        Set(ByVal value As String)
            Links.Clear()

            If value.Contains("[") Then
                Dim re As New Regex("\[(.+?) (.+?)\]")

                While True
                    Dim m = re.Match(value)

                    If m.Success Then
                        Links.Add(m.Index, m.Groups(2).Value.Length, m.Groups(1).Value)
                        value = value.Replace(m.Value, m.Groups(2).Value)
                    Else
                        Exit While
                    End If
                End While
            End If

            MyBase.Text = value
        End Set
    End Property

    Protected Overrides Sub OnLinkClicked(ByVal e As LinkLabelLinkClickedEventArgs)
        Dim t = e.Link.LinkData.ToString

        If t.StartsWith("mailto:") OrElse t.StartsWith("http://") Then
            Process.Start(t)
        End If

        MyBase.OnLinkClicked(e)
    End Sub
End Class