“蝴蝶飞出窗体后重新定位到左下方再向右上方飞”这是我们的VB期末考试题,求解啊!

2025-02-27 11:15:13
推荐回答(2个)
回答1:

有现成的程序(整个工程),带动画的,要不要,要就留邮箱

代码:

Private Sub cmdEnd_Click()

  End

End Sub

Private Sub Form_Load()

'初始定位左下角

ImaMain.Move 0, Me.Height - ImaMain.Height - 305

Timer1.Enabled = True

End Sub

Private Sub Timer1_Timer()

    Static ImaBmp As Integer

    ImaMain.Move ImaMain.Left + 20, ImaMain.Top - 5 '移动图片

    '以下为图片变换蝴蝶翅膀张开及合上,实现动画效果

    If ImaBmp Then

        ImaMain.Picture = ImaOpenWings.Picture

    Else

        ImaMain.Picture = ImaCloseWings.Picture

    End If

    ImaBmp = Not ImaBmp

    

    '判断蝴蝶是否飞出窗口外面,是则回至左下角

    If ImaMain.Left >= Me.Width Or ImaMain.Top < -ImaMain.Height Then

       ImaMain.Move 0, Me.Height - ImaMain.Height - 305

    End If

End Sub

回答2:

说个思路吧 上班没编程环境
假如蝴蝶的在picture1里面
事件用
Private Sub Timer_Timer()
with Picture1
if .left>me.width or .top<0 then '如果他到达缘则重置
.left=0
.top=me.height
else '没达到边缘时向右上方前进
.left=.left+80
.top=.top-60
end if
end with
end sub
.