I'm designing a form that populates a rich text box from a text file. Certain lines in the text box have to be of a different style (different color and weight). I looked at numerous examples and think I have coded it correctly but whatever I do the style never updates / changes for the desired lines. It's always the default font from the form designer.
Any ideas why I cannot get the "SelectedText" method for Rich Text Box component to work?
Thanks!
Here's the code I am calling to populate the rich text box component:
`this.rtbTraysTested.Text = "";`
foreach (string uid in ticket.TraysTested().Keys)
{
// Append Tray UID to the text box and select it
this.rtbTraysTested.SelectionStart = this.rtbTraysTested.Text.Length;
this.rtbTraysTested.Text += uid;
this.rtbTraysTested.SelectionLength = uid.Length;
// Text settings
if (ticket.TraysTested()[uid] > 1) // Highlight entry if tray has been tested more than once
{
this.rtbTraysTested.SelectionColor = Color.OrangeRed;
this.rtbTraysTested.SelectionFont = new Font(this.rtbTraysTested.Font, FontStyle.Regular);
}
else
{
this.rtbTraysTested.SelectionColor = Color.White;
this.rtbTraysTested.SelectionFont = new Font(this.rtbTraysTested.Font, FontStyle.Regular);
}
this.rtbTraysTested.Text += Environment.NewLine; // Add the endline to entry
this.rtbTraysTested.Select(0, 0); // Deselect the text
}