title: How to set a textbox to allow only numbers, one (1) comma, AND a dash (for negative numbers) at the beginning
body: <p>This is one is a different box than the usual "i want only numbers in a textBox"</p>
  
  <p>I came across with the need to use <strong>negative</strong> numbers, and I'd rather take them in a text box.</p>
  
  <p>So far we can easily set decimals using the following code</p>
  
  <pre><code>  private void textBox_KeyPress_1(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>
  
  <p>And hooking it on the desired boxes in the designer
      this.textBoxXX.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox_KeyPress_1);</p>
  
  <p>So far so good, but, what if i need to add a "-" and allow it only in the beginning of the code? any hint?</p>