多谢相助!

解决方案 »

  1.   

    这样?Option ExplicitPrivate Sub Form_Load()
        Me.KeyPreview = True
    End SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Dim dX As Integer
        Dim dY As Integer
        
        Select Case KeyCode
            Case vbKeyLeft
                dX = -1
            Case vbKeyRight
                dX = 1
            Case vbKeyUp
                dY = -1
            Case vbKeyDown
                dY = 1
        End Select
        
        With Picture1
            .Move .Left + dX, .Top + dY
        End With
    End Sub
      

  2.   

    我也有过这种想法,但是Keydown单独解决不了这样的问题,只有API了(最起码我在KeyDown里没有实现)
      

  3.   

    那就加个Timer吧~Option ExplicitPrivate Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As IntegerPrivate Sub Form_Load()
        Timer1.Interval = 10
        Timer1.Enabled = True
    End SubPrivate Sub Timer1_Timer()
        Dim dX As Integer
        Dim dY As Integer
        
        If GetAsyncKeyState(vbKeyLeft) Then dX = -1
        If GetAsyncKeyState(vbKeyRight) Then dX = 1
        If GetAsyncKeyState(vbKeyUp) Then dY = -1
        If GetAsyncKeyState(vbKeyDown) Then dY = 1
        
        If (dX Or dY) <> 0 Then
            With Picture1
                .Move .Left + dX, .Top + dY
            End With
        End If
    End Sub
      

  4.   

    一般情况下,只要遇到三根烟之内还不能实现的代码,就转向API吧——我的建议
      

  5.   

    我觉得API就很好,我以前写小游戏的时候就想过KeyDown和KeyPress来接收,可是最后还是用API实现的
      

  6.   

    X_Saint(嘘嘘)  能不能给点代码提示一下
      

  7.   

    真对不住,我现在不在自己的电脑旁边。你可以去Google用完全搜索找找看。
    Google的完全搜索就是把搜索内容用"扩起来,在查找
    我把我的Mail给你,[email protected]
    我回家后把代码给你Mail过去
      

  8.   

    我的邮址是:[email protected]
    我一会儿发一邮件给你
      

  9.   

    Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 87 Then
        Picture1.Top = Picture1.Top - 100
    ElseIf KeyCode = 83 Then
        Picture1.Top = Picture1.Top + 100
    ElseIf KeyCode = 65 Then
        Picture1.Left = Picture1.Left - 100
    ElseIf KeyCode = 68 Then
        Picture1.Left = Picture1.Left + 100
    End If
    End Sub当picture1获得焦点时能实现移动~~
      

  10.   

    楼上的代码是用wsda  控制上下左右的~~
      

  11.   

    用Private Sub Picture1_KeyPress(KeyAscii As Integer)也可以吧!
      

  12.   

    这个问题我以前遇到过,这样就行了:
    放一个PICTURE1及多个别的什么控件,以备测试之用。
    Private Sub Form_Load()
    Me.Show
    Me.KeyPreview = True '让窗体接受按键
    Picture1.TabIndex = 0 '让PICTURE获得焦点
    End SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    With Picture1 '使用WITH语句,锁定焦点
        Select Case KeyCode
            Case vbKeyDown
                .Top = .Top + Screen.TwipsPerPixelY
            Case vbKeyUp
                .Top = .Top - Screen.TwipsPerPixelY
            Case vbKeyLeft
                .Left = .Left - Screen.TwipsPerPixelX
            Case vbKeyRight
                .Left = .Left + Screen.TwipsPerPixelX
        End Select
    End WithEnd Sub这是一位外国朋友教我的,要谢可谢他,不过,分数加给我好了~~~hehe
    那位朋友帮我解决的问题:
    http://www.vbgamer.com/msgboard/topic.asp?TOPIC_ID=218