MBrendecke icon

GiddleTestOptimized

MBrendecke | PRO | 04/02/19 11:19:21 PM UTC | 0 ⭐ | 349 👁️ | Never ⏰ | []
C# |

1.04 KB

|

None

|

0 👍

/

0 👎

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