daily pastebin goal
92%
SHARE
TWEET

Untitled

a guest Nov 22nd, 2017 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. TextBox tb = new TextBox();
  2. this.Controls.Add(tb);
  3.    
  4. private void tb_KeyPress(object sender, KeyPressEventArgs e)
  5. {
  6.     if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) )
  7.     {
  8.         e.Handled = true;
  9.     }
  10. }
  11.    
  12. tb.KeyPress += tb_KeyPress;
  13.    
  14. TextBox tb = new TextBox();
  15. tb.KeyPress  += tb_KeyPress; //add this
  16. this.Controls.Add(tb);
  17.  
  18. private void tb_KeyPress(object sender, KeyPressEventArgs e)
  19. {
  20.    if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) )
  21.    {
  22.     e.Handled = true;
  23.    }
  24. }
RAW Paste Data
Top