title: Matching brackets and indentation in RichTextBox using C#?
body: <p>I want to make a Code Editing control that can format text somewhat like Visual Studio,till now i have implemented syntax highlighting and autocompletion but i want to format text in nested curly braces.For example:Consider a for loop,</p>
  
  <pre><code>for(int i=0;i&lt;=10;i++)
  {
  Function_One();              //This should be a tab away from first brace
  Function_Two();              //So with this
  if(a==b)                     //So with this
  {                            //This should be four tabs away from first brace
  MessageBox.Show("Some text");//This should be six tabs away from first brace
  }                            //This should be four tabs away from first brace
  }
  </code></pre>
  
  <p>now what i want is that this should look something like this,</p>
  
  <pre><code>for(int i=0;i&lt;=10;i++)
  {
     Function_One();              
     Function_Two();              
     if(a==b)                     
     {                            
        MessageBox.Show("Some text");
     }                            
  }
  </code></pre>
  
  <p>I have already tried Regular Expressions but at some point they fail to match,so i tried to match it with code but code cannot match very deeply nested code or is very hard to implement
  ,so is there any way to achieve this,and one more thing i am doing all this in Winforms control RichTextBox using C#.</p>