using System;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace GiddleTest1
{
public partial class Form1 : Form
{
private Regex R;
public Form1()
{
InitializeComponent();
InitRegex();
}
private void InitRegex()
{
R = new Regex(String.Join("|", new[]{
"IF", "THEN", "ELSE", "ENDIF"
}));
}
private void rtbText_TextChanged(object sender, EventArgs e)
{
int index = rtbText.SelectionStart;
rtbText.SuspendLayout();
foreach (Match m in R.Matches(rtbText.Text))
{
rtbText.SelectionStart = m.Index;
rtbText.SelectionLength = m.Length;
rtbText.SelectionColor = Color.Blue;
rtbText.SelectionStart = index;
}
rtbText.SelectionColor = Color.Black;
rtbText.ResumeLayout(true);
}
}
}
Comments