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? :ehh:
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
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?
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
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:
Dim lines As String() = myRichTextBox.Lines
lines(lines.Length - 1) = "This line will replace the last line in the RTB"
myRichTextBox.Lines = lines