我正在使用visual basic,我正在创建一个函数来搜索输入到richtextbox 中的每个单词。当一个词被输入到RichTextBox2
搜索中时RichTextBox1
,文本被突出显示。
RichTextBox1
并且RiochTextBox2
是只读的,RichTextBox2
可以通过代码写入,而RichTextBox1
只有默认文本(单词目录)。也有RichTextBox3
其中持有RichTextBox2's
文本的副本
RichTextBox3.Text = RichTextBox2.Text
这是函数的代码。
public class textsearch
Private intPosition As Integer
Private Sub NextButton_Click(sender As Object, e As EventArgs) Handles NextButton.Click
generatekanji()
' Static intStart As Integer
'used to select compare method
Dim intStart As Integer
Dim objType As Object
Dim lastWord As String = RichTextBox2.Text.Split(" ").Last
objType = CompareMethod.Text
'set starting position to 1
intPosition = 1
'use the InStr function to look up a staring position of a search string in a given text box using objType (case-insensitive or case-sensitive)
intStart = InStr(intPosition, RichTextBox1.Text, lastWord, objType) ' what it searches
If intStart > 0 Then
'set starting select position on a textbox and select the search string
RichTextBox1.SelectionStart = intStart - 1
RichTextBox1.SelectionLength = lastWord.Length 'highlights the searched word
RichTextBox1.Select()
End If
End Sub
End Class
这是一个非常有用的功能,但主要问题是
(1) 因为RichTextBox1
是只读的,所以每次执行搜索时都会发出“叮”的声音,这很烦人。
(2) I am unable to find a way to select the character whenever a word is found , or how to replace the word in RichTextBox3
with the character next to the searched word.
Could someone help with this problem .