如何在C#.net的Web应用程序的文本框中突出显示搜索文本

问题描述:

大家好,
我正在将word文档显示在文本框中.
现在,我要突出显示多行文本框中的搜索文本.

Hi All,
I am displaying the word document in to textbox.
Now i want to highlight the search text in muliti line textbox.

您可以应用于文本框的唯一突出显示是选择-就像您双击一个文本框一样.字-没有特定的突出显示.为了使它正常工作,您需要一个RichTextBox.

在TextBox中选择特定文本很容易:
The only highlight you can apply to a TextBox is Selection - just as if you had double clicked a word - there is no specific Highlight. For that to work properly, you need a RichTextBox.

To select specific text in a TextBox is easy:
myTextBox.SelectionStart = indexOfFirstCharacterToSelect;
myTextBox.SelectionLength = numberOfCharactersToSelect;

您可能需要添加

myTextBox.ScrollToCaret();

,以确保所选文本可见.

to ensure that the selected text is visible.


< pre>< pre>< pre>< code>< code> ;< code></code></code></code></code</pre></pre</pre>< b>< b< b> b> b< b>小<小>小<小<大>大& gt;&> < a href ="></a>< a href ="></a>< a href ="></a>< a href ="&gt ;</a>< a href ="></a>< a href ="></a>< a href ="></a>< a href ="></a>< a href ="></a></big></big></small></small></small> ;</b</b</b</b></b>
<pre><pre><pre><code><code><code><code></code></code></code></code></pre></pre></pre><b><b><b><b><b><small><small><small><big><big>&gt;&gt;&gt;&amp;<a href=""></a><a href=""></a><a href=""></a><a href=""></a><a href=""></a><a href=""></a><a href=""></a><a href=""></a><a href=""></a></big></big></small></small></small></b></b></b></b></b>