Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Coloring text in RichEditBox

weiccoweicco Member Posts: 950
This is related to my last question...

When I insert text to RichEditBox, I do like this:

[code]
string text = "Some text
";
int start = richTextBox1.Text.Length;

richTextBox1.Text += text;
richTextBox1.Select(start, text.Length);
richTextBox1.SelectionColor = Color.Orange;
[/code]

This works on first time. Text is colored to orange. But when called second time only the last line is colored orange, everything else is turned back to black (default foreground color). Even when I color something in the middle of the text and then call that, only last line goes to orange, everything else is black. Any ideas?

Comments

  • athomasathomas Member Posts: 228
    Hi,

    you need to make the Control "intelligent" that is make it remember that all its content has been modified. You need to write an event handler for this may be

    private void onTextChange(object sender, EventArgs e)
    {
    //set Selection Color to Orange

    richtextBox1.SelectionColor = Color.Orange;
    richtextBox1.Text = richtextBox1.SelecionColor;

    }

    I didnt tested it but it makes sense to me.
    You store the Color value on the Text property each time this handle is loaded.

    Cheers.
    Alex


    : This is related to my last question...
    :
    : When I insert text to RichEditBox, I do like this:
    :
    : [code]
    : string text = "Some text
    ";
    : int start = richTextBox1.Text.Length;
    :
    : richTextBox1.Text += text;
    : richTextBox1.Select(start, text.Length);
    : richTextBox1.SelectionColor = Color.Orange;
    : [/code]
    :
    : This works on first time. Text is colored to orange. But when called second time only the last line is colored orange, everything else is turned back to black (default foreground color). Even when I color something in the middle of the text and then call that, only last line goes to orange, everything else is black. Any ideas?
    :

Sign In or Register to comment.