Richtextbox formatting between events

Hello all,

I am using a richtextbox to read information in when a use clicks a button.  on every click i need to display a differet color for the text.  What happens is that all my previous formating is lost and only the latest is saved.  Is there a way to prevent this from happening.

I am currently using the following method to add the new text to the box


ImportTextBox.Text &= NewText

 


I then select the new text and apply the formatting, like i said previously only the latest changes stick the others are removed.  Any help with this would be great.  Thanks


Answer this question

Richtextbox formatting between events

  • Sidd Shenoy



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim MyString As String = "This is a Test"

    Me.RichTextBox1.AppendText(MyString)

    Me.RichTextBox1.SelectionStart = Me.RichTextBox1.TextLength - MyString.length

    Me.RichTextBox1.SelectionLength = MyString.Length

    If Me.CheckBox1.CheckState = CheckState.Checked Then

    Me.RichTextBox1.SelectionColor = Color.Blue

    Else

    Me.RichTextBox1.SelectionColor = Color.Green

    End If

    Me.RichTextBox1.SelectionStart = Me.RichTextBox1.TextLength

    End Sub





     


  • Richtextbox formatting between events