vb的一个关于timer的问题

来源:百度知道 编辑:UC知道 时间:2024/06/01 18:44:19
一个圆扩大再缩小再扩大的代码,缩不小,哪位大侠帮我看看怎么缩小?Private Sub Command1_Click()
r = Picture1.Width / 50
Picture1.FillStyle = 0
Picture1.FillColor = vbRed
Timer1.Enabled = True
Timer1.Interval = 100
Timer2.Enabled = True
Timer2.Interval = 100
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False
End Sub

Private Sub Timer1_Timer()
If r < Picture1.Width / 2 Then
r = r + Picture1.Width / 100
Picture1.Circle (Picture1.Width / 2, Picture1.Height / 2), r
End If
End Sub

Private Sub Timer2_Timer()
If r = Picture1.Width / 2 Then
r = r - Picture1.Width / 100
Picture1.Circle (Picture1.Width / 2, Picture1.Height / 2), r
End If
End Sub
还有,就是一开始要有一个小圆,最后缩小的时候缩到最小是小圆大小

用一个时钟就够了,再定义一个flag的通用变量,用来切换

Dim r As Integer, flag As Boolean
Private Sub Command1_Click()
r = Picture1.Width / 50
Picture1.FillStyle = 0
Picture1.FillColor = vbRed
Timer1.Enabled = True
Timer1.Interval = 100
flag = True
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
If flag = True Then
r = r + Picture1.Width / 100
If r > Picture1.Width / 2 Then flag = False
Else
Picture1.Cls
r = r - Picture1.Width / 100
If r < Picture1.Width / 50 Then flag = True
End If
Picture1.Circle (Picture1.Width / 2, Picture1.Height / 2), r
End Sub

问题就是r - Picture1.Width / 100是否小于Picture1.Width / 2
因为一旦小于就会运行timer1的代码

我有个想法就是用多一个timer控件来控制前两个timer的enabled属性
一旦达到timer2的条件就停止timer1打开timer2 达到timer1的条件则打开timer1停