Help modifying text
-
Hi i'm having problems here I made this code but after it finds and p I try to write more stuff but it gets stuck selecting the p. Can anyone help me out here with the codes? Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Try RichTextBox1.SelectionStart = RichTextBox1.Find("p") Dim SelectorFont As New Font(RichTextBox1.Font, FontStyle.Bold) RichTextBox1.SelectionFont = SelectorFont RichTextBox1.SelectionColor = RichTextBox1.SelectionColor.Black Catch ex As Exception End Try
-
Hi i'm having problems here I made this code but after it finds and p I try to write more stuff but it gets stuck selecting the p. Can anyone help me out here with the codes? Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Try RichTextBox1.SelectionStart = RichTextBox1.Find("p") Dim SelectorFont As New Font(RichTextBox1.Font, FontStyle.Bold) RichTextBox1.SelectionFont = SelectorFont RichTextBox1.SelectionColor = RichTextBox1.SelectionColor.Black Catch ex As Exception End Try
Hi Rylogy! i'm having problems here I made this code but after it finds and p I try to write more stuff but it gets stuck selecting the p. You simply forgot to change the length of the selection using the
SelectionLength
property.RichTextBox1.SelectionLength = "p".Length
You might also want to use a more generic approach right from the start by supporting strings with any length. A first prototype of a method might look like this:
Private Sub HighlightText(ByVal Highlight As String)
Dim NextPosition As Integer = 0
Do
NextPosition = RichTextBox1.Find(Highlight, NextPosition, _
RichTextBoxFinds.None)
If NextPosition > -1 Then
RichTextBox1.SelectionStart = NextPosition
RichTextBox1.SelectionLength = Highlight.Length
Dim SelectorFont As New Font(RichTextBox1.Font, _
FontStyle.Bold)
RichTextBox1.SelectionFont = SelectorFont
RichTextBox1.SelectionColor = Color.Black
NextPosition += Highlight.Length
Else
Exit Do
End If
Loop
End SubThe next step would be to replace the hard-coded object
RichTextBox1
with an object variable. Best regards Dennis -
Hi Rylogy! i'm having problems here I made this code but after it finds and p I try to write more stuff but it gets stuck selecting the p. You simply forgot to change the length of the selection using the
SelectionLength
property.RichTextBox1.SelectionLength = "p".Length
You might also want to use a more generic approach right from the start by supporting strings with any length. A first prototype of a method might look like this:
Private Sub HighlightText(ByVal Highlight As String)
Dim NextPosition As Integer = 0
Do
NextPosition = RichTextBox1.Find(Highlight, NextPosition, _
RichTextBoxFinds.None)
If NextPosition > -1 Then
RichTextBox1.SelectionStart = NextPosition
RichTextBox1.SelectionLength = Highlight.Length
Dim SelectorFont As New Font(RichTextBox1.Font, _
FontStyle.Bold)
RichTextBox1.SelectionFont = SelectorFont
RichTextBox1.SelectionColor = Color.Black
NextPosition += Highlight.Length
Else
Exit Do
End If
Loop
End SubThe next step would be to replace the hard-coded object
RichTextBox1
with an object variable. Best regards Dennis -
Hi Rylogy! i'm having problems here I made this code but after it finds and p I try to write more stuff but it gets stuck selecting the p. You simply forgot to change the length of the selection using the
SelectionLength
property.RichTextBox1.SelectionLength = "p".Length
You might also want to use a more generic approach right from the start by supporting strings with any length. A first prototype of a method might look like this:
Private Sub HighlightText(ByVal Highlight As String)
Dim NextPosition As Integer = 0
Do
NextPosition = RichTextBox1.Find(Highlight, NextPosition, _
RichTextBoxFinds.None)
If NextPosition > -1 Then
RichTextBox1.SelectionStart = NextPosition
RichTextBox1.SelectionLength = Highlight.Length
Dim SelectorFont As New Font(RichTextBox1.Font, _
FontStyle.Bold)
RichTextBox1.SelectionFont = SelectorFont
RichTextBox1.SelectionColor = Color.Black
NextPosition += Highlight.Length
Else
Exit Do
End If
Loop
End SubThe next step would be to replace the hard-coded object
RichTextBox1
with an object variable. Best regards Dennis