在我的应用程序中,我使用名为Fastcoloredtextbox的文本框控件,但由于它继承了文本框控件,因此它应该是同样的解决方案。尝试只替换文本框中的一个字符串实例
我添加了用户在我的应用程序中单击某个单词的功能,然后打开一个打开的文件对话框,然后用户可以选择一个文件,并用文件名替换单击的单词。这是我期望完成的,除了一个问题...它用文件名替换文本框中同一个单词的每个实例。我不确定如何只取代被点击的单词。任何帮助,将不胜感激。
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
clickedword字符串是被点击的实际单词。
编辑:我想出了一个解决方案,开始选择项目被点击并选择完整的单词。当它被选中时,可以插入文本,使其替换选定的单词。感谢那些提供建议的人。
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
@JonB:不重复。 OP想要*当前选择的字符串的任何*实例。 – Neolisk
为什么这是封闭的重复?这显然不一样。 – user1632018
绝对不是。我会帮你重新投票。 – Neolisk