我想制作一个VB程序,运行后,按住"左箭头",picture1就向左移动,按住"右箭头"就向右移动...???

 我来答
szqaly
推荐于2016-09-03 · TA获得超过1745个赞
知道大有可为答主
回答量:2107
采纳率:77%
帮助的人:1588万
展开全部

窗体上放一个Picture1,两个按钮,一个时钟Timer1控件

 

Enum DirectionConst
    toLeft = 1
    toRight = 2
    noMove = 0
End Enum
Dim Direction As DirectionConst
Const StepCount = 100
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Timer1.Enabled = True
    Direction = toLeft
End Sub
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Direction = noMove
End Sub
Private Sub Command2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Timer1.Enabled = True
Direction = toRight
End Sub
Private Sub Command2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Direction = noMove
End Sub
Private Sub Form_Load()
    Timer1.Interval = 60
End Sub
Private Sub Timer1_Timer()
    Select Case Direction
        Case noMove
            Timer1.Enabled = False
        Case toRight
            Picture1.Left = Picture1.Left + StepCount
        Case toLeft
            Picture1.Left = Picture1.Left - StepCount
    End Select
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式