A1VBCode Forums

Underline Only the Last Word in Richtextbox


http://www.a1vbcode.com/vbforums/Topic32334.aspx

By ryoka012 - 10/26/2015

Hi experts,



I have this code but this is on click event button to underline the last word.

but this is in click event using button.



How can i convert this on keydown event with



If e.KeyCode = Keys.Space Then



End If





Dim count As String = RichTextBox1.Text

Dim LastWord As String = count.Split(" ").Last()

Dim index As Integer = RichTextBox1.Find(LastWord, 0, RichTextBoxFinds.WholeWord)

If index <> -1 Then



RichTextBox1.SelectionStart = index

RichTextBox1.SelectionLength = LastWord.Length

RichTextBox1.SelectionFont = New Font("Courier New", 15, FontStyle.Underline)

End If





Thanks.
By zack - 10/26/2015

Add the code to the RichTextBox1_KeyDown event.