2017-10-19 4 views
0

에에서 KeyDown에서 (키 값)을 두 배로 변수를 변환하는 방법 :이 코드가 Visual Basic의

Private Sub key(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown 
    If e.KeyValue = Keys.Enter Then 
     If FuSt = False Then 
      FuSt = True 
      My.Computer.Audio.Play(My.Settings.Full) 
     Else 
      FuSt = False 
      My.Computer.Audio.Play(DIRECOTRY) 
     End If 
    End If 
    If e.KeyValue = b1 Then 
     My.Computer.Audio.Play(SoundsDir & "1.wav") 
    End If 
End Sub 

을하지만 (키보드의 Z 버튼) B1을 연주 할 때이 오류가 있습니다

Conversation from "z" to Double is incorrect (Somethink like that)

도와 주시겠습니까?

+0

비교에서 문자열과 열거 형을 함께 사용하는 것은 좋지 않습니다. 대신 KeyPress 이벤트를 사용하여 "z"와 같은 타이핑 키를 감지하십시오. –

+1

'b1'을'Keys.Z'로 대체 하시겠습니까? – PerpetualStudent

답변

0

변수 b1에 키를 할당하려면 다음과 같이하십시오.

Keys은 enum입니다. (권장) KeyPress 이벤트를 사용하려면

Dim b1 As Keys 
b1 = Keys.Z 

한스 옆모습 코멘트처럼, 코드 ​​아래에보십시오.

Private Sub Form1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress 
     If e.KeyChar = Char.ToLower(ChrW(Keys.Z)) Then 
      MsgBox("Z selecetd") 
     End If 
    End Sub 

또는 KeyDown 이벤트로 이동하려면 다음 코드를 시도하십시오.

Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown 
    If e.KeyCode.Equals(Keys.Z) Then 
     MsgBox("Z selecetd") 
    End If 
End Sub 
+0

예, 알아요,하지만 Keys.z이 변수 b1에 있습니다. – Metexu

+0

키는 열거 형입니다 .... 그럼 시도해 볼 수 있습니다 ..... 키로 dim b1 ..... – Naidu

+0

할당하는 동안. ... b1 = Keys.Z – Naidu