Skip to content

Instantly share code, notes, and snippets.

@hbsnow
Created December 31, 2014 05:17
Show Gist options
  • Save hbsnow/ecda9da7083e50abfc06 to your computer and use it in GitHub Desktop.
Save hbsnow/ecda9da7083e50abfc06 to your computer and use it in GitHub Desktop.
数値入力に必要なキー以外を無効化する
private void KeyPressNumberOnly(Object sender, KeyEventArgs e)
{
if ((e.Key < Key.D0 || e.Key > Key.D9) &&
(e.Key < Key.NumPad0 || e.Key > Key.NumPad9) &&
e.Key != Key.Back &&
e.Key != Key.Delete &&
e.Key != Key.Left &&
e.Key != Key.Right &&
e.Key != Key.Tab)
{
e.Handled = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment