问题描述
基本上我想要做的是让图片框向上,然后向左,然后向下,然后向右,所有这些都基于计时器滴答.我是新手,所以我真的不知道出了什么问题.如果你们能给出一个简单的答案或更好的方法,那就太好了.
Basically what I'm trying to do is to make a picture box go up, then left, then down, then right, all based on timer ticks. I'm fairly new so I don't really know what's wrong. If you guys could give a simple answer or a better approach, that'd be great.
Dim slides As Integer
slides += 10
If slides < 20 Then
PictureBox1.Left += 10
ElseIf slides > 20 AndAlso slides < 40 Then
PictureBox1.Top += 10
ElseIf slides > 40 AndAlso < 60 Then
PictureBox1.Left -= 10
ElseIf slides > 60 AndAlso < 80 Then
PictureBox1.Top -= 10
Else
slides = 0
End If
推荐答案
两件事.确保您的 slides
整数在 Tick 事件之外.此外,请确保涵盖您的代码不会检查的equals"条件,因此 slides
不断落入else"类别并设置回零.也就是说,当 slides
等于 20 时,你没有满足它的条件,所以它重置为零.
Two things. Make sure your slides
integer is outside the Tick event. Also, make sure to cover the condition of "equals", which your code doesn't check for, so slides
is constantly falling into the "else" category and setting back to zero. That is, when slides
equals 20, you don't have a condition that satisfies it, so it resets to zero.
Private slides As Integer
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
slides += 10
If slides <= 20 Then
PictureBox1.Left += 10
ElseIf slides > 20 AndAlso slides <= 40 Then
PictureBox1.Top += 10
ElseIf slides > 40 AndAlso slides <= 60 Then
PictureBox1.Left -= 10
ElseIf slides > 60 AndAlso slides <= 80 Then
PictureBox1.Top -= 10
Else
slides = 0
End If
End Sub
这篇关于使用定时器移动图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!