View difference between Paste ID: 6aqNGhg9 and 1GSU9fzc
SHOW: | | - or go back to the newest paste.
1
using System;
2
using System.Drawing;
3
using System.Text.RegularExpressions;
4
using System.Windows.Forms;
5
6
namespace GiddleTest1
7
{
8
    public partial class Form1 : Form
9
    {
10
        private Regex R;
11
12
        public Form1()
13
        {
14
            InitializeComponent();
15
            InitRegex();
16
        }
17-
            string[] befehle =
17+
18
        private void InitRegex()
19-
                "IF", "THEN", "ELSE", "ENDIF" // Befehle vervollständigen...
19+
20-
            };
20+
            R = new Regex(String.Join("|", new[]{
21
                "IF", "THEN", "ELSE", "ENDIF"
22-
            string pattern = String.Join("|", befehle);
22+
            }));
23
        }
24-
            Regex R = new Regex(pattern);
24+
25
        private void rtbText_TextChanged(object sender, EventArgs e)
26
        {
27
            int index = rtbText.SelectionStart;
28
            rtbText.SuspendLayout();
29
30
            foreach (Match m in R.Matches(rtbText.Text))
31
            {
32
                rtbText.SelectionStart = m.Index;
33
                rtbText.SelectionLength = m.Length;
34
                rtbText.SelectionColor = Color.Blue;
35
                rtbText.SelectionStart = index;
36
            }
37
38
            rtbText.SelectionColor = Color.Black;
39
            rtbText.ResumeLayout(true);
40
        }
41
    }
42
}