public form()

{
initializeComponent();

textbox.text.keypress + = new keypressEventHandler(text.box_keypress);

}

Now drag and down a textbox and click on "Keypress event"

private void textbox_keypress(obj sender, event e)

{
char pressedkey = e.keychar;

if(char.IsLetter(pressedkey)||char.IsSeparator(PressedKey)||char.IsPunction(pressedKey))

{

e.handled = false;

}

else

e.handled = true;

}