在我的应用程序中,我使用了一个名为 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