如何让文本框中某一指定字符串高亮显示?

解决方案 »

  1.   

    Text1.SelStart = 2
    Text1.SelLength = 5
    Text1.SetFocus
      

  2.   

    Private Sub Command1_Click()
        Text2.SetFocus
        Text2.SelStart = InStr(1, Text2, Text1) - 1
        Text2.SelLength = Len(Text1)
        
    End SubPrivate Sub Form_Load()
        Text1 = "s"
        Text2 = "miss"
    End Sub
    多关键字只要循环即可
      

  3.   

    InStr(1, Text2, Text1) - 1
    关键要使用模式匹配的一些算法
      

  4.   

    同时多个不同的关键字高亮显示
    最好用RichTextBox,用不同颜色表示不同的关键字
    方法和text类似
      

  5.   

    Text1.SelStart = 2   <----你想从哪位开始高亮
    Text1.SelLength = 5  <----亮的字符串有多长
    Text1.SetFocus