title: Only allow two digits after decimal in textbox?
body: <p>I have a textbox where the user enters a number, but how can i make it so that if they type the '.' after it it only allows 2 decimal places?</p>
  
  <pre><code>private void textBox1_KeyPress(object sender, KeyPressEventArgs e) 
  { 
      if (!char.IsControl(e.KeyChar)  
          &amp;&amp; !char.IsDigit(e.KeyChar)  
          &amp;&amp; e.KeyChar != '.') 
      { 
          e.Handled = true; 
      } 
  
      // only allow one decimal point 
      if (e.KeyChar == '.'  
          &amp;&amp; (sender as TextBox).Text.IndexOf('.') &gt; -1) 
      { 
          e.Handled = true; 
      } 
  }
  </code></pre>