Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Help modifying text

Help modifying text

Scheduled Pinned Locked Moved Visual Basic
helpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rylogy
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • R Rylogy

      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

      D Offline
      D Offline
      Dennis C Dietrich
      wrote on last edited by
      #2

      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 Sub

      The next step would be to replace the hard-coded object RichTextBox1 with an object variable. Best regards Dennis

      R 2 Replies Last reply
      0
      • D Dennis C Dietrich

        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 Sub

        The next step would be to replace the hard-coded object RichTextBox1 with an object variable. Best regards Dennis

        R Offline
        R Offline
        Rylogy
        wrote on last edited by
        #3

        thank you

        1 Reply Last reply
        0
        • D Dennis C Dietrich

          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 Sub

          The next step would be to replace the hard-coded object RichTextBox1 with an object variable. Best regards Dennis

          R Offline
          R Offline
          Rylogy
          wrote on last edited by
          #4

          hmm Private Sub HighlightText(ByVal Highlight As String) what's that for?

          R 1 Reply Last reply
          0
          • R Rylogy

            hmm Private Sub HighlightText(ByVal Highlight As String) what's that for?

            R Offline
            R Offline
            Rylogy
            wrote on last edited by
            #5

            whoa it worked

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups