Is there any way to highlight text in textbox?

132 views Asked by At

I am beginner to vb.net, currently I'm doing a web project which needs to compare 2 text file and highlight the differences. I have been using jQuery highlightTextarea trying to highlight the differences, but I'm still unable to do it. Is there any other way to do it?

Here is my code:

<script type="text/javascript">
    $('TextBox2').highlightTextarea({
        words: ['(', ')']
    });
</script>
1

There are 1 answers

0
Josh On

The vb.net method is to set the text box selection with .Select and refer to or change the selection with .SelectedText. Note that this is a functional selection and will only work for one continuous portion of the text. If you are looking for a cosmetic highlighting feature this will not work. Based on the above, I believe what you want should be:

Dim sStart As Integer, sEnd As Integer
sStart = InStr(TextBox2.Text, "(")
sEnd = InStr(TextBox2.Text, ")")
TextBox2.Select(sStart, sEnd - sStart + 1)