Jan 5, 2014

C# Make A TextBox Accept Only Numeric Values


  • You First Have To Go To The Properties Of The Textbox And Find For The Event Keypress And Double Click The Event Then You Will Get A New Event Like Below ..


         private void textbox1_KeyPress(object sender, KeyPressEventArgs e)
             {
            
              }


  • Now All You Have To Copy The Code Below And Paste It Inside The Event Function...


            char keypress = e.KeyChar;
            if (char.IsDigit(keypress) || e.KeyChar == Convert.ToChar(Keys.Back))
            {
                //eventChecker("T");
            }
            else
            {
                e.Handled = true;
            }

  • And It Should Look Like This .. When Done.. 

            private void textbox1_KeyPress(object sender, KeyPressEventArgs e)

                {
                    char keypress = e.KeyChar;
                    if (char.IsDigit(keypress) || e.KeyChar == Convert.ToChar(Keys.Back))
                    {
                          //eventChecker("T");
                     }
                         else
                         {
                               e.Handled = true;
                         }

                 }
     

No comments:

JWT Token Decode Using Jquery

When it come to authentication we use many mechanism. Ones the user authenticated we must keep these details somewhere safe. So we can share...