I am pretty sure someone else can do this better, but here is a solution.
If nothing else, you can use what I did as a rough template and improve on
it.
----------------------------
Private Sub RichTextBox1_MouseDown(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseDown
If e.Button = MouseButtons.Right Then
Dim CharIndex As Int32
Dim StartPos As Int32
Dim EndPos As Int32
Dim SelText As String
Dim Options() As String
Dim SelItem As String
Dim RunningLength As Int32
' get the position of the character they clicked at
CharIndex = RichTextBox1.GetCharIndexFromPosition(New Point(e.X,
e.Y))
' find the start and end of the option list
EndPos = RichTextBox1.Text.IndexOf("]", CharIndex) + 1
StartPos = RichTextBox1.Text.LastIndexOf("[", CharIndex)
' leave if they did not click inside of an option
If EndPos = -1 Or StartPos = -1 Or StartPos > EndPos Then
Exit Sub ' not inside of a [] section
End If
CharIndex -= StartPos
' select the total text area of the option list
RichTextBox1.Select(StartPos, EndPos - StartPos)
' get the total text area of the option list
SelText = RichTextBox1.SelectedText
Options = SelText.Split("|")
' find the item the user click on
For Each SelItem In Options
RunningLength += SelItem.Length + 1
If CharIndex < RunningLength Then
' found the item they selected, display that item
RichTextBox1.SelectedText = SelItem.Replace("[",
"").Replace("]", "")
Exit For
End If
Next
End If
End Sub
-------------------------------------
PS. still has some issues if there is more then one option list
HJ Majoue said:
I am having a problem with RichTextBox Control and hope you can help.
I am working on a VB.Net project that has a RTB control, the user opens a
form template. What I want to do is for a user to be able to click or right
click on text within the form such as Priority: [[|Low|Medium|High]]. If
the user clicked on Low the brackets and bars would go away and leave
Priority: Low. And the same for Medium and High.