private void ColorAllAppearencesInRichTextBox(RichTextBox richTextBox, string appearence, Color color, int start)
{
int current = 0;
RichTextBoxFinds options = RichTextBoxFinds.MatchCase;
Action action = () => start = richTextBox.Find(appearence, start, options);
richTextBox.Invoke(action);
while (start >= 0)
{
action = () => richTextBox.SelectionStart = start;
richTextBox.Invoke(action);
action = () => richTextBox.SelectionLength = appearence.Length;
richTextBox.Invoke(action);
action = () => richTextBox.SelectionColor = color;
richTextBox.Invoke(action);
current = start + appearence.Length;
int tempRichTextBoxTextLength = 0;
action = () => tempRichTextBoxTextLength = richTextBox.TextLength;
richTextBox.Invoke(action);
if (current < tempRichTextBoxTextLength)
{
action = () => start = richTextBox.Find(appearence, current, options);
richTextBox.Invoke(action);
}
else
{
if(color == Color.Red)
{
currentRed = current;
}
else if (color == Color.Green)
{
currentGreen = current;
}
break;
}
}
}
{
int current = 0;
RichTextBoxFinds options = RichTextBoxFinds.MatchCase;
Action action = () => start = richTextBox.Find(appearence, start, options);
richTextBox.Invoke(action);
while (start >= 0)
{
action = () => richTextBox.SelectionStart = start;
richTextBox.Invoke(action);
action = () => richTextBox.SelectionLength = appearence.Length;
richTextBox.Invoke(action);
action = () => richTextBox.SelectionColor = color;
richTextBox.Invoke(action);
current = start + appearence.Length;
int tempRichTextBoxTextLength = 0;
action = () => tempRichTextBoxTextLength = richTextBox.TextLength;
richTextBox.Invoke(action);
if (current < tempRichTextBoxTextLength)
{
action = () => start = richTextBox.Find(appearence, current, options);
richTextBox.Invoke(action);
}
else
{
if(color == Color.Red)
{
currentRed = current;
}
else if (color == Color.Green)
{
currentGreen = current;
}
break;
}
}
}
Beim ersten Run:
0 als start mitgeben,
sonst Wert in globalen Variablen zwischenspeichern und diese als start mitgeben:
private int currentRed = 0;
private int currentGreen = 0;
Keine Kommentare:
Kommentar veröffentlichen