黄翅鱼的做法窍门:vb,关于我做的这个简单的蓄力槽的东西

来源:百度文库 编辑:中科新闻网 时间:2024/05/11 18:39:40
我想做个类似蓄力槽的东西,高手指点一下
Dim x As Integer

Private Sub form_KeyDown(KeyCode As Integer, Shift As Integer)

x = 1
If KeyCode = vbKeySpace Then
Timer1.Enabled = True

End If
End Sub

Private Sub Timer1_Timer()

x = x + 10

Picture1.Line (0, 0)-(x, Picture1.Height), , B

End Sub

可是总是按空格蓄力到一定距离的时候就莫名其妙地停止了,松手后又继续

很纳闷。。。高手帮我看看代码有什么问题没

谢谢!

Dim isDown As Boolean

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 32 Then isDown = True
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
isDown = False
End Sub

Private Sub Timer1_Timer()
Static x As Integer

If isDown Then
x = x + 10
Picture1.Line (0, 0)-(x, Picture1.Height), , B
Else
x = 0
End If
End Sub

楼上的程序可以运行。但要加入下面的代码:

Private Sub Form_Load()
Form1.KeyPreview = True
Timer1.Interval = 1
End Sub

另外,在Timer1_Timer()中加入一句Picture1.Cls,在反复演示的效果要更好些。如下:
Private Sub Timer1_Timer()
Static x As Integer
If isDown Then
x = x + 10
Picture1.Line (0, 0)-(x, Picture1.Height), , B
Else
x = 0
Picture1.Cls '加在这里
End If
End Sub