I'm displaying hex data in a Rich Text Box, that looks like this:
64 73 67 66 34 33 74 67 35 34 36 79 37 35 79 36
33 67 35 36 67 35 36 33 79 68 34 36 37 38 72 74
and I want it to be displayed with every 3 characters being a different colour. i.e. each bit (2 numbers and a space to be specific) being a different colour.
What I've tried to do is simply set the text colour to blue in designer mode, in order to halve the processing time. Then I'll just change every 2nd 3 characters to red.
However, this is what's happening:
Here is the code:
for (int i = 0; i < richTextBox1.TextLength; i++)
if (i % 4 == 1)
{
richTextBox1.SelectionStart = i;
richTextBox1.SelectionLength = 2;
richTextBox1.SelectionColor = Color.Red;
}
It's apparent my math is wrong, I just can't think of anything that will work. I've tried i % 3 = 0, selectionLength = 3, and many others.
P.S. If this will be slow, can you suggest any other methods of doing it? here is the full code if you want to see it: http://pastebin.com/vHMfnZW1