G
Groide
Hello, I'm crazy but I want create an editor with c# and
System.Windows.Forms.RichTextBox.
I have many difficult to create the effect to highlights the text and to
close the tags.
This is my code:
int cursor = richTextBox.SelectionStart;
Regex attrs = new Regex(@"<\/?\w+(\s+\w+=""(\w+)"")*>");
MatchCollection matches = attrs.Matches(richTextBox.Text);
foreach (Match match in matches)
{
GroupCollection groups = match.Groups;
Group group = groups[0];
CaptureCollection captures = group.Captures;
for (int i = 0; i < captures.Count; i++)
{
string word = captures.Value;
int index = captures.Index;
richTextBox.Select(index, word.Length);
richTextBox.SelectionColor = Color.DarkBlue;
richTextBox.DeselectAll();
}
Group groupAttrs = groups[2];
CaptureCollection capturesAttrs = groupAttrs.Captures;
for (int i = 0; i < capturesAttrs.Count; i++)
{
string word = capturesAttrs.Value;
int index = capturesAttrs.Index;
richTextBox.Select(index, word.Length);
richTextBox.SelectionColor = Color.Green;
richTextBox.DeselectAll();
}
}
that color html tag in blue and value of attribute in green
BUT
the effect of flickers is horrible (es. select -> color -> deselect ->
select -> color ..etc...)
Any suggestions?
System.Windows.Forms.RichTextBox.
I have many difficult to create the effect to highlights the text and to
close the tags.
This is my code:
int cursor = richTextBox.SelectionStart;
Regex attrs = new Regex(@"<\/?\w+(\s+\w+=""(\w+)"")*>");
MatchCollection matches = attrs.Matches(richTextBox.Text);
foreach (Match match in matches)
{
GroupCollection groups = match.Groups;
Group group = groups[0];
CaptureCollection captures = group.Captures;
for (int i = 0; i < captures.Count; i++)
{
string word = captures.Value;
int index = captures.Index;
richTextBox.Select(index, word.Length);
richTextBox.SelectionColor = Color.DarkBlue;
richTextBox.DeselectAll();
}
Group groupAttrs = groups[2];
CaptureCollection capturesAttrs = groupAttrs.Captures;
for (int i = 0; i < capturesAttrs.Count; i++)
{
string word = capturesAttrs.Value;
int index = capturesAttrs.Index;
richTextBox.Select(index, word.Length);
richTextBox.SelectionColor = Color.Green;
richTextBox.DeselectAll();
}
}
that color html tag in blue and value of attribute in green
BUT
the effect of flickers is horrible (es. select -> color -> deselect ->
select -> color ..etc...)
Any suggestions?