日期:2014-05-18  浏览次数:20744 次

C# keypress事件问题
if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8)
  {
  e.Handled = true;
  }
  if (e.KeyChar == 8)
  {
  e.Handled = false;
  }

当中的48、57、8各代表什么意思?

------解决方案--------------------
查看asii码
------解决方案--------------------
ascii码值,百度一下
------解决方案--------------------
8是空格
48是0
57是9
------解决方案--------------------
keycode 8 = BackSpace
keycode 9 = Tab Tab
keycode 12 = Clear
keycode 13 = Enter
keycode 16 = Shift_L
keycode 17 = Control_L
keycode 18 = Alt_L
keycode 19 = Pause
keycode 20 = Caps_Lock
keycode 27 = Escape Escape
keycode 32 = space space
keycode 33 = Prior
keycode 34 = Next
keycode 35 = End
keycode 36 = Home
keycode 37 = Left
keycode 38 = Up
keycode 39 = Right
keycode 40 = Down
keycode 41 = Select
keycode 42 = Print
keycode 43 = Execute
keycode 45 = Insert
keycode 46 = Delete
keycode 47 = Help
keycode 48 = 0 equal braceright
keycode 49 = 1 exclam onesuperior
keycode 50 = 2 quotedbl twosuperior
keycode 51 = 3 section threesuperior
keycode 52 = 4 dollar
keycode 53 = 5 percent
keycode 54 = 6 ampersand
keycode 55 = 7 slash braceleft
keycode 56 = 8 parenleft bracketleft
keycode 57 = 9 parenright bracketright
keycode 65 = a A
keycode 66 = b B
keycode 67 = c C
keycode 68 = d D
keycode 69 = e E EuroSign
keycode 70 = f F
......
------解决方案--------------------
48~57是ascii码 分别对应键盘上的 0~9 键
8 表示 空格键
------解决方案--------------------
探讨

8是空格
48是0
57是9

------解决方案--------------------
探讨

48~57是ascii码 分别对应键盘上的 0~9 键
8 表示 空格键