Advertisement
Guest User

Untitled

a guest
Jan 6th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1.        private void richTextBox1_TextChanged(object sender, EventArgs e) {
  2.             int ln = 0;
  3.             int sel = richTextBox1.SelectionStart;
  4.             foreach (string s in richTextBox1.Lines) {
  5.                 int index = commentOut(richTextBox1.Lines[ln]);
  6.                 if(richTextBox1.Lines.Length > 0
  7.                     && richTextBox1.Lines[ln].Contains("#")) {
  8.                      richTextBox1.Select(index, richTextBox1.Lines[ln].Length);
  9.                      richTextBox1.SelectionColor = Color.Green;
  10.                      richTextBox1.Select(0, richTextBox1.Lines[ln].Length - index);
  11.                      richTextBox1.SelectionColor = Color.Black;
  12.                      //richTextBox1.Select(sel, 0);
  13.                      richTextBox1.Select(sel, 0);
  14.                     return;
  15.                 }
  16.                 ln++;
  17.             }
  18.             this.CheckKeyword("while", Color.Purple, 0);
  19.             this.CheckKeyword("if", Color.Green, 0);
  20.         }
  21.  
  22.         private int commentOut(String line) {
  23.             char[] ar = line.ToCharArray();
  24.             int ln = 0;
  25.             foreach(char s in ar) {
  26.                 if(s.ToString().Equals("#")) {
  27.                     break;
  28.                 }
  29.                 ln++;
  30.             }
  31.             return ln;
  32.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement