Martin Voda
Martin Voda

Reputation: 19

RichTextBox in Visual Studio

I have a question about Rich Text Box in VS2010.

I have RTB in project and i have any commands for servos in each line in RTB. I send the command for servo from lines in RTB. I need highlight(underline, bold,...whatever) line in RTB from which i send a command for servo.

For example: This is lines from my RTB, and now i send command for servo from line 5.

1 1200

2 1400

3 1100

4 1300

5 1880

6 1400

7 1660

How can i do this in VS in c #?

Thank you very much.

Upvotes: 0

Views: 686

Answers (1)

Zroq
Zroq

Reputation: 8392

If every line of your RTB Text begins with a number and a space you can try this:

string[] textBoxLines = richTextBox1.Lines;
for (int i = 0; i < textBoxLines.Length; i++)
{
    string line = textBoxLines[i];
    if (line.StartsWith("3 ")) // define the line number which the commands occurred
    {
        richTextBox1.SelectionStart = richTextBox1.GetFirstCharIndexFromLine(i);
        richTextBox1.SelectionLength = line.Length;
        richTextBox1.SelectionFont  = new Font(richTextBox1.SelectionFont, FontStyle.Bold);
    }
}
// clear the selection
richTextBox1.SelectionLength = 0;

Upvotes: 2

Related Questions