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!

Highlight Selected Text

Status
Not open for further replies.

mytaurus2000

Technical User
Oct 4, 2006
138
US
I am programming a simple word processor. How do you highlight the text after the word search? Here is my code:

Dim Target As String
Dim FoundPos As Single

Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
FoundPos = InStr(1, txtMemo.Text, txtTarget.Text)
txtMemo.SelectionStart = IIf(FoundPos > 0, FoundPos - 1, 0)
txtMemo.SelectionLength = IIf(FoundPos > 0, Len(Target), 0)
End Sub
 
When I click btnFind, the focus is sent to the word, but it doesn't highlight the searched word.
 
Where are you assigning text to the variable Target? You either need to assign txtTarget.Text to Target or use Len(txtTarget.Text)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top