title: Format C# code with indents programmatically
body: <p>I'm making a C# application including a <code>RichTextBox</code> in which the user will be able to put some C# code in it and format it by indents like what Visual Studio does.</p>
  
  <pre><code>private void btnEdit_Click(object sender, EventArgs e)
  {
    //rchCode.Text= formattedCode; // Which I haven't got anywhere so far
  }
  </code></pre>
  
  <p>I looked for the same questions and <a href="https://stackoverflow.com/a/681812/2263683">this answer</a> suggests using something called <a href="http://www.narrange.net/" rel="noreferrer">NArrange</a>, but I don't want use other tools, add-ins or such.</p>
  
  <p>Also <a href="https://stackoverflow.com/a/681648/2263683">this one</a> offering the CodeDOM way which I haven't figure it out how to use it (<em>If it's helpful in anyway</em>)</p>
  
  <p>I want to do it by writing some actual code. How can I do it?</p>