In my application I am using a textbox control called Fastcoloredtextbox, although since it inherits the textbox control, it should be the same solution to do this.
I added the ability for the user to click on a word in my application and it then opens an open file dialog, the user can then select a file and it replaces the word that was clicked with the filename. This is what I am looking to accomplish, except for one problem...It replaces every instance of the same word in the textbox with this filename. I am unsure how to only have it replace the word that was clicked though. Any help would be appreciated.
Private Sub tb_VisualMarkerClick(sender As Object, e As VisualMarkerEventArgs)
Dim page As RadPageViewPage = RadPageView1.SelectedPage
Dim txt As FastColoredTextBox = TryCast(page.Controls(0), FastColoredTextBox)
Dim ofd As New OpenFileDialog
ofd.FileName = ""
ofd.Filter = "Image Files (*.bmp, *.jpg)|*.bmp;*.jpg"
If ofd.ShowDialog = DialogResult.OK
Then
Dim ClickedWord As String = (TryCast(e.Marker, RangeMarker).range.Text)
txt.Text = txt.Text.Replace(ClickedWord, ofd.FileName)
End If
End Sub
The clickedword string is the actual word that was clicked.
EDIT: I have came up with a solution that starts a selection where the item was clicked and selects the full word. When it is selected, text can be inserted causing it to replace the selected word. Thank you for those who offered up advice.
Private Sub tb_VisualMarkerClick(sender As Object, e As VisualMarkerEventArgs)
Dim page As RadPageViewPage = RadPageView1.SelectedPage
Dim txt As FastColoredTextBox = TryCast(page.Controls(0), FastColoredTextBox)
txt.Invalidate()
txt.Selection.Start = New Place((TryCast(e.Marker, RangeMarker).range).Start.iChar, (TryCast(e.Marker, RangeMarker).range).Start.iLine)
txt.SelectionLength = (TryCast(e.Marker, RangeMarker).range).Text.Length
Dim ClickedWord As String = (TryCast(e.Marker, RangeMarker).range.Text)
If ClickedWord = "path" Then
Dim ofd As New OpenFileDialog
ofd.FileName = ""
ofd.Filter = "Image Files (*.bmp, *.jpg)|*.bmp;*.jpg"
If ofd.ShowDialog = DialogResult.OK Then
txt.InsertText(ofd.FileName)
End If
End If
End Sub