Results 1 to 5 of 5

Thread: Overwrite line in RichTextBox

  1. #1

    Thread Starter
    Lively Member drdress's Avatar
    Join Date
    Jul 2009
    Location
    Copenhagen, Denmark
    Posts
    76

    Overwrite line in RichTextBox

    I'm writing to a RichTextBox using the with command:

    Code:
    With RichTextBox
      .AppendText("blablabla" & vbCrLf)
      .ScrollToCaret()
    End With
    But sometimes I would like to overwrite what I've just written instead of writing it on the next line. Is there a way to do this?

  2. #2
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Overwrite line in RichTextBox

    you can rotate on each line like:

    Code:
    for each rt in richtextbox1.lines
    if rt.text = 'bla bla' then
      rt.text = 'bla bla bla'
    end if 
    next
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  3. #3

    Thread Starter
    Lively Member drdress's Avatar
    Join Date
    Jul 2009
    Location
    Copenhagen, Denmark
    Posts
    76

    Re: Overwrite line in RichTextBox

    Isn't there a way to only acces the last line (since this is the one I wanna change). So I can avoid the for loop?

  4. #4
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Overwrite line in RichTextBox

    i just tried my example and it didn't work, so igonre it.
    i'll play with it and get back to you if i'll find a solution
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Overwrite line in RichTextBox

    You do need to use the Lines property but it's value is not live, i.e. making changes to it doesn't change the contents of the control. You need to change the array and then assign it back to the property:
    vb.net Code:
    1. Dim lines As String() = myRichTextBox.Lines
    2.  
    3. lines(lines.Length - 1) = "This line will replace the last line in the RTB"
    4. myRichTextBox.Lines = lines
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width