1
votes

I would like to print the output of an algorithm (C#,.NET 4.0)in a listview control or a multiline textbox(or rich textbox) strings containing some characters which are in a different color.For example:

ABCAAAGGGJHHJK (whole string black)
     AHGGJI (H and I - red)
    BAJMGC  (B -green, J,M,C-red)

I know it is possible to change the text color & font for the whole control, but is it possible to generate it like this? Do you have any suggestions?

1

1 Answers

1
votes

You can't easily do it with a ListBox, unless you're willing to draw the items manually (which is a pain). It would probably be even harder with a TextBox. However, you can do it with a RichTextBox.

richTextBox.SelectionColor = Color.Black;
richTextBox.AppendText("ABCAAAGGGJHHJK\n");
richTextBox.AppendText("A");
richTextBox.SelectionColor = Color.Red;
richTextBox.AppendText("H");
richTextBox.SelectionColor = Color.Black;
richTextBox.AppendText("GGJ");
richTextBox.SelectionColor = Color.Red;
richTextBox.AppendText("I");
// and so on...