2014-11-04 51 views
0

所以我试图让游戏对我们的最后一个项目(高中),我们最近从VB6 swaped到新的Visual Basic 2010的工作。但今天我的问题是,whever我尝试使用KeyDown事件和从其他程序调用它都有点吃力得到箭头键路过的时候通过功能

KeyValue = _5x5_Board_KeyDown(KeyValue) 

据标记它,因为它不包含所使用的“发件人”或“E”为活动激活。如果我把这些输入到程序的调用中,它说它们没有被定义。但据我所知,它们是系统定义的。

Public Class _5x5_Board 
Dim xpos As Integer 
Dim ypos As Integer 
Dim Tile(6, 6) As PictureBox 
Dim KeyValue As Integer 

Private Sub _5x5_Board_Load(ByVal sender As System.Object) 
    'Test start position (center of the board) 
    xpos = 3 
    ypos = 3 

    'Assisgning all of the picture boxes to the array 
    'You can ignore this part... 
    Tile(0, 1) = Tile0_1 
    Tile(0, 2) = Tile0_2 
    Tile(0, 3) = Tile0_3 
    Tile(0, 4) = Tile0_4 
    Tile(0, 5) = Tile0_5 

    Tile(1, 0) = Tile1_0 
    Tile(1, 1) = Tile1_1 
    Tile(1, 2) = Tile1_2 
    Tile(1, 3) = Tile1_3 
    Tile(1, 4) = Tile1_4 
    Tile(1, 5) = Tile1_5 
    Tile(1, 6) = Tile1_6 

    Tile(2, 0) = Tile2_0 
    Tile(2, 1) = Tile2_1 
    Tile(2, 2) = Tile2_2 
    Tile(2, 3) = Tile2_3 
    Tile(2, 4) = Tile2_4 
    Tile(2, 5) = Tile2_5 
    Tile(2, 6) = Tile2_6 

    Tile(3, 0) = Tile3_0 
    Tile(3, 1) = Tile3_1 
    Tile(3, 2) = Tile3_2 
    Tile(3, 3) = Tile3_3 
    Tile(3, 4) = Tile3_4 
    Tile(3, 5) = Tile3_5 
    Tile(3, 6) = Tile3_6 

    Tile(4, 0) = Tile4_0 
    Tile(4, 1) = Tile4_1 
    Tile(4, 2) = Tile4_2 
    Tile(4, 3) = Tile4_3 
    Tile(4, 4) = Tile4_4 
    Tile(4, 5) = Tile4_5 
    Tile(4, 6) = Tile4_6 

    Tile(5, 0) = Tile5_0 
    Tile(5, 1) = Tile5_1 
    Tile(5, 2) = Tile5_2 
    Tile(5, 3) = Tile5_3 
    Tile(5, 4) = Tile5_4 
    Tile(5, 5) = Tile5_5 
    Tile(5, 6) = Tile5_6 

    Tile(6, 1) = Tile6_1 
    Tile(6, 2) = Tile6_2 
    Tile(6, 3) = Tile6_3 
    Tile(6, 4) = Tile6_4 
    Tile(6, 5) = Tile6_5 

    Call GamePlay(xpos, ypos, KeyValue) 
End Sub 

Private Sub GamePlay(ByRef xpos As Integer, ByRef ypos As Integer, ByRef KeyValue As Integer) 
    Do 
     'Sends for answer of the KeyDown event. 
     'This is the problem bellow 
     KeyValue = _5x5_Board_KeyDown(KeyValue) 
     'Decides the position the tile should move to pased on numeric order 
     Select Case KeyValue 
      'Up 
      Case Is = 1 
       xpos = xpos - 1 
       'Right 
      Case Is = 2 
       ypos = ypos + 1 
       'Down 
      Case Is = 3 
       xpos = xpos + 1 
       'Left 
      Case Is = 4 
       ypos = ypos - 1 
     End Select 
     'Colours in the new square on the board of the designated tile 
     Tile(xpos, ypos).Load("H:\Computing\Project\TileJump\TileJump\TileJump\Resources\Select1.bmp") 
    Loop Until Keys.Escape = True 
End Sub 

Private Function _5x5_Board_KeyDown(ByRef KeyValue As Integer, ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown 
    'This is to declare the key pressed to a numeric value that is used to declare the new position 
    If e.KeyCode = Keys.Up Then 
     KeyValue = 1 
     'MsgBox("KeyValue is " & KeyValue) 
    ElseIf e.KeyCode = Keys.Right Then 
     KeyValue = 2 
     'MsgBox("KeyValue is " & KeyValue) 
    ElseIf e.KeyCode = Keys.Down Then 
     KeyValue = 3 
     'MsgBox("KeyValue is " & KeyValue) 
    ElseIf e.KeyCode = Keys.Left Then 
     KeyValue = 4 
     'MsgBox("KeyValue is " & KeyValue) 
    End If 
    Return KeyValue 
End Function 
End Class 

以上是我的代码到目前为止。我希望它有帮助。这可能听起来很愚蠢和坏的我,但我一直坚持在这近一个月

+0

的方式键手柄返回d在VB.NET中与VB6中处理的方式有很大的不同(在某些方面更糟糕),您需要在这方面进行一些研究。 – 2014-12-10 08:41:55

回答

0

该keydown函数接受三个参数:键值(你有),发送者为对象(对象类型),E作为EventArgs的(你按了哪个键)

然而,当你调用的keydown功能,你只有经过第一个参数:从该keydown函数内的keyValue

改为调用游戏(),而不是其他办法解决,这样一来就会有一个整数,而不是与发送者越来越复杂和EventArgs的

+0

谢谢你,你不知道如何furstrating这是......作为编程的方式进入。过去的一个问题到下一个:D再次感谢! – 2014-11-18 09:34:48