Wednesday, 22 August 2012

Keypress Event Function


Following function are called the block of textbox or any other tools event keypress function

Only Integer :

        public void int_key(object sender, KeyPressEventArgs e)  
        {
            if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 24 && e.KeyChar != 3 && e.KeyChar != 46 && e.KeyChar != 22 && (e.KeyChar != 8))
                e.Handled = true;
        }

Only Character :

        public void char_key(object sender, KeyPressEventArgs e) 
        {
            if ((e.KeyChar < 65 || e.KeyChar > 90) && (e.KeyChar < 97 || e.KeyChar > 122) && e.KeyChar != 46 && e.KeyChar != 32 && e.KeyChar != 64 && e.KeyChar != 24 && e.KeyChar != 3 && e.KeyChar != 22 && (e.KeyChar != 8))
                e.Handled = true;
        }

Character and Integer 

        public void char_int_key(object sender, KeyPressEventArgs e) 
        {
            if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar < 65 || e.KeyChar > 90) && (e.KeyChar < 97 || e.KeyChar > 122) && e.KeyChar != 32 && e.KeyChar != 3 && e.KeyChar != 22 && (e.KeyChar != 8))
                e.Handled = true;
        }

No comments:

Post a Comment