Switch case Tastenabfrage klappt nicht

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von RushDen.

    Switch case Tastenabfrage klappt nicht

    Hi Leute.
    Ich wollte mal fragen, warum bei folgendem Event nichts passiert wenn ich eine Taste drücken.
    Die textbox bleibt leer, und wenn ich A drücke kommt auch keine MSGBOX.
    Hier mal der code:

    VB.NET-Quellcode

    1. Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    2. Select Case e.KeyCode
    3. Case Keys.A
    4. TextBox1.Text = TextBox1.Text + "a"
    5. MsgBox("a")
    6. Case Keys.Q
    7. TextBox1.Text = TextBox1.Text + "q"
    8. Case Keys.W
    9. TextBox1.Text = TextBox1.Text + "w"
    10. Case Keys.E
    11. TextBox1.Text = TextBox1.Text + "e"
    12. Case Keys.R
    13. TextBox1.Text = TextBox1.Text + "r"
    14. Case Keys.T
    15. TextBox1.Text = TextBox1.Text + "t"
    16. Case Keys.Z
    17. TextBox1.Text = TextBox1.Text + "z"
    18. Case Keys.U
    19. TextBox1.Text = TextBox1.Text + "u"
    20. Case Keys.I
    21. TextBox1.Text = TextBox1.Text + "i"
    22. Case Keys.O
    23. TextBox1.Text = TextBox1.Text + "o"
    24. Case Keys.P
    25. TextBox1.Text = TextBox1.Text + "p"
    26. Case Keys.D
    27. TextBox1.Text = TextBox1.Text + "d"
    28. Case Keys.S
    29. TextBox1.Text = TextBox1.Text + "s"
    30. Case Keys.F
    31. TextBox1.Text = TextBox1.Text + "f"
    32. Case Keys.G
    33. TextBox1.Text = TextBox1.Text + "g"
    34. Case Keys.H
    35. TextBox1.Text = TextBox1.Text + "h"
    36. Case Keys.J
    37. TextBox1.Text = TextBox1.Text + "j"
    38. Case Keys.K
    39. TextBox1.Text = TextBox1.Text + "k"
    40. Case Keys.L
    41. TextBox1.Text = TextBox1.Text + "l"
    42. Case Keys.Y
    43. TextBox1.Text = TextBox1.Text + "y"
    44. Case Keys.X
    45. TextBox1.Text = TextBox1.Text + "x"
    46. Case Keys.C
    47. TextBox1.Text = TextBox1.Text + "c"
    48. Case Keys.V
    49. TextBox1.Text = TextBox1.Text + "v"
    50. Case Keys.B
    51. TextBox1.Text = TextBox1.Text + "b"
    52. Case Keys.N
    53. TextBox1.Text = TextBox1.Text + "n"
    54. Case Keys.M
    55. TextBox1.Text = TextBox1.Text + "m"
    56. Case Keys.Alt
    57. TextBox1.Text = TextBox1.Text + " <Alt> "
    58. Case Keys.Back
    59. TextBox1.Text = TextBox1.Text + " <Zurück> "
    60. Case Keys.CapsLock
    61. TextBox1.Text = TextBox1.Text + " <Grosschreib> "
    62. Case Keys.Control
    63. TextBox1.Text = TextBox1.Text + " <Strg> "
    64. Case Keys.Delete
    65. TextBox1.Text = TextBox1.Text + " <Löschen> "
    66. Case Keys.Down
    67. TextBox1.Text = TextBox1.Text + " <Runter> "
    68. Case Keys.Enter
    69. TextBox1.Text = TextBox1.Text + " <Enter> " + vbCrLf
    70. Case Keys.Escape
    71. TextBox1.Text = TextBox1.Text + " <Escape> "
    72. Case Keys.F1
    73. TextBox1.Text = TextBox1.Text + " <F1> "
    74. Case Keys.F2
    75. TextBox1.Text = TextBox1.Text + " <F2> "
    76. Case Keys.F3
    77. TextBox1.Text = TextBox1.Text + " <F3> "
    78. Case Keys.F4
    79. TextBox1.Text = TextBox1.Text + " <F4> "
    80. Case Keys.F5
    81. TextBox1.Text = TextBox1.Text + " <F5> "
    82. Case Keys.F6
    83. TextBox1.Text = TextBox1.Text + " <F6> "
    84. Case Keys.F7
    85. TextBox1.Text = TextBox1.Text + " <F7> "
    86. Case Keys.F8
    87. TextBox1.Text = TextBox1.Text + " <F8> "
    88. Case Keys.F9
    89. TextBox1.Text = TextBox1.Text + " <F9> "
    90. Case Keys.F10
    91. TextBox1.Text = TextBox1.Text + " <F10> "
    92. Case Keys.F11
    93. TextBox1.Text = TextBox1.Text + " <F11> "
    94. Case Keys.F12
    95. TextBox1.Text = TextBox1.Text + " <F12> "
    96. Case Keys.F13
    97. TextBox1.Text = TextBox1.Text + " <F13> "
    98. Case Keys.LButton
    99. TextBox1.Text = TextBox1.Text + " <Maus links> "
    100. Case Keys.LControlKey
    101. TextBox1.Text = TextBox1.Text + " <Strg links> "
    102. Case Keys.Left
    103. TextBox1.Text = TextBox1.Text + " <Links> "
    104. Case Keys.NumLock
    105. TextBox1.Text = TextBox1.Text + " <NumLock> "
    106. Case Keys.NumPad0
    107. TextBox1.Text = TextBox1.Text + " <0> "
    108. Case Keys.NumPad1
    109. TextBox1.Text = TextBox1.Text + " <1> "
    110. Case Keys.NumPad2
    111. TextBox1.Text = TextBox1.Text + " <2> "
    112. Case Keys.NumPad3
    113. TextBox1.Text = TextBox1.Text + " <3> "
    114. Case Keys.NumPad4
    115. TextBox1.Text = TextBox1.Text + " <4> "
    116. Case Keys.NumPad5
    117. TextBox1.Text = TextBox1.Text + " <5> "
    118. Case Keys.NumPad6
    119. TextBox1.Text = TextBox1.Text + " <6> "
    120. Case Keys.NumPad7
    121. TextBox1.Text = TextBox1.Text + " <7> "
    122. Case Keys.NumPad8
    123. TextBox1.Text = TextBox1.Text + " <8> "
    124. Case Keys.NumPad9
    125. TextBox1.Text = TextBox1.Text + " <9> "
    126. Case Keys.PageDown
    127. TextBox1.Text = TextBox1.Text + " <Bild runter> "
    128. Case Keys.PageUp
    129. TextBox1.Text = TextBox1.Text + " <Bild rauf> "
    130. Case Keys.RButton
    131. TextBox1.Text = TextBox1.Text + " <Maus rechts> "
    132. Case Keys.Return
    133. TextBox1.Text = TextBox1.Text + " <Return> "
    134. Case Keys.Right
    135. TextBox1.Text = TextBox1.Text + " <Rechts> "
    136. Case Keys.Shift
    137. TextBox1.Text = TextBox1.Text + " <Shift> "
    138. Case Keys.Up
    139. TextBox1.Text = TextBox1.Text + " <Hoch> "
    140. Case Keys.Space
    141. TextBox1.Text = TextBox1.Text + (" ")
    142. End Select
    143. End Sub

    Ich hoffe ihr könnt mihr helfen. Ich habe bestimmt nur was ganz simples übersehen, finde es aber nicht.
    Danke schonmal.
    shutdown

    shutdown schrieb:

    Ich habe bestimmt nur was ganz simples übersehen
    Gib Deiner Form im Designer KeyPreview = True.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!