VB关于选中文本框的文字的小问题

有两个文本框。分别为text1和text2。一个按钮 我想就是在text1里输入文字。然后text2自动跳到相应的文字而且选中。 比如:text2里文本是“1234567890987654321” 然后在text1里输入“2”,然后text2自动跳到"2"里并选中“2” 点击按钮后跳到下一个“2”并选中。 请问应该怎样编

第1个回答  2020-04-16
先设置
text2.HideSelection
=false
这个需要在属性窗口设置
Private
Sub
Command1_Click()
Startme
=
Text2.SelLength
+
Text2.SelStart
+
1
'给变量赋值
Where2
=
InStr(Startme,
Text2.Text,
Text1.Text)
'令其从上次找到的地方找起
If
Where2
Then
Text2.SelStart
=
Where2
-
1
Text2.SelLength
=
Len(Text1.Text)
End
If
End
Sub
Private
Sub
Text1_Change()
If
InStr(Text2.Text,
Text1.Text)
>
0
Then
Text2.SelStart
=
InStr(Text2.Text,
Text1.Text)
-
1
Text2.SelLength
=
Len(Text1.Text)
End
If
End
Sub
相似回答