Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextBox Highlight Words Question

Status
Not open for further replies.

sonya9879

Programmer
Jun 18, 2004
147
CA
hi is it possible to hightlight words within a readonly textbox? I written a highlight function to highlight text but the html tags that does the highlight doesn't render in the textbox? I am wondering if is it possible to do this or not? Been trying several different things but didn't work so far.
 
Can you post the code you have written? Maybe that would give us a clearer understanding of what you are doing and what isn't working.
 
var = "hello how are you tell me please how"

textbox1.Text = highlight("how",var,"<span class=highlight>", "</span>")


Function Highlight(ByVal SearchWord As String, _
ByVal InputTxt As String, _
ByVal StartTag As String, _
ByVal EndTag As String) As String

Return Regex.Replace(InputTxt, "\b(" & Regex.Escape(SearchWord) & ")\b", _
StartTag & "$1" & EndTag, RegexOptions.IgnoreCase)

End Function


All this works fine BUT in the textbox area I get the <span > tag instead of what I want, the word hightlighted in a different color
 
You won't be able to do this with a standard Textbox control, however there are quite a few free Rich Text Box controls that will give you this functionality


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top