Hey Guys im currently stuck in writing a Debug function where my Exception should gets printed in Red to an RichTextBox. I tried different solutions i've found here but they are not working, so i think i'm doing something wrong.
Here is my Function where the Text gets printed in Red:
public void DebugHighlighter(string s)
{
/*
richTextBoxOutput.SelectionColor = Color.Red;
richTextBoxOutput.SelectedText = s;
richTextBoxOutput.SelectionColor = Color.Red;
richTextBoxOutput.Text += s + "\n";
richTextBoxOutput.Find(s);
*/
richTextBoxOutput.SelectionColor = Color.Red;
richTextBoxOutput.AppendText(s);
richTextBoxOutput.AppendText("\n");
int index = richTextBoxOutput.Text.IndexOf(s);
int lenght = s.Length;
richTextBoxOutput.Select(index, lenght);
}
Here is the function that gives the string to the DebugHighlighter:
try
{
if (!reversed)
{
string outputSplitter = Regex.Replace(output2[19], @"[a-zA-z]", " ");
outputBandwith = outputSplitter.Split(" ", StringSplitOptions.RemoveEmptyEntries);
bandwithResult = outputBandwith[3];
}
else if (reversed)
{
string outputSplitter = Regex.Replace(output2[20], @"[a-zA-z]", " ");
outputBandwith = outputSplitter.Split(" ", StringSplitOptions.RemoveEmptyEntries);
bandwithResult = outputBandwith[3];
}
}
catch(IndexOutOfRangeException ex)
{
OutputConsoleForm._OutputConsoleForm.DebugHighlighter("Index out of Range");
}
I will also attach an Screenshot of the Output(I put a box on the Output which should be printed in red).
I hope someone can tell me the little or bigger thing which im doing wrong here. I already looked on reddit/stackoverflow/msdn but no variant works out for me.