3个回答
展开全部
所需要控件:shape1,timer1,command1,command2
Dim degree As Single
Const pi = 3.1415926
Dim v As Integer
Dim r As Single
Private Sub Command1_Click()
Timer1.Enabled = False
Form_Load
End Sub
Private Sub Command2_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Me.Show
Shape1.Shape = 3
Timer1.Enabled = False
Timer1.Interval = 100
Shape1.Left = Me.Width * Rnd
Shape1.Top = Me.Height * Rnd
degree = 2 * pi * Rnd
v = 150
r = 1
Command1.Caption = "结束"
Command2.Caption = "开始"
End Sub
Private Sub Timer1_Timer()
If Shape1.Top > 0 And Shape1.Left > 0 And (Shape1.Left + Shape1.Width) < Me.Width And (Shape1.Top + Shape1.Height) < Me.Height Then
Shape1.Top = Shape1.Top + Sin(degree) * v * r
Shape1.Left = Shape1.Left + Cos(degree) * v * r
v = v * r
Else
Timer1.Enabled = False
Call chagestate
End If
End Sub
Public Sub chagestate()
If Shape1.Top <= 0 Or (Shape1.Top + Shape1.Height) >= Me.Height Then
degree = 2 * pi - degree
If Shape1.Top <= 0 Then Shape1.Top = 1
If (Shape1.Top + Shape1.Height) >= Me.Height Then Shape1.Top = Me.Height - Shape1.Height - 1
End If
If Shape1.Left <= 0 Or (Shape1.Left + Shape1.Width) >= Me.Width Then
If (Shape1.Left + Shape1.Width) >= Me.Width Then Shape1.Left = Me.Width - Shape1.Width - 1
If Shape1.Left <= 0 Then Shape1.Left = 1
If degree < pi / 2 Then degree = pi / 2 + degree
If degree > pi / 2 And degree < pi Then degree = 3 * pi / 2 - degree
If degree > pi Or degree < 2 * pi Then degree = 3 * pi - degree
End If
v = 150
Timer1.Enabled = True
End Sub
Dim degree As Single
Const pi = 3.1415926
Dim v As Integer
Dim r As Single
Private Sub Command1_Click()
Timer1.Enabled = False
Form_Load
End Sub
Private Sub Command2_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Me.Show
Shape1.Shape = 3
Timer1.Enabled = False
Timer1.Interval = 100
Shape1.Left = Me.Width * Rnd
Shape1.Top = Me.Height * Rnd
degree = 2 * pi * Rnd
v = 150
r = 1
Command1.Caption = "结束"
Command2.Caption = "开始"
End Sub
Private Sub Timer1_Timer()
If Shape1.Top > 0 And Shape1.Left > 0 And (Shape1.Left + Shape1.Width) < Me.Width And (Shape1.Top + Shape1.Height) < Me.Height Then
Shape1.Top = Shape1.Top + Sin(degree) * v * r
Shape1.Left = Shape1.Left + Cos(degree) * v * r
v = v * r
Else
Timer1.Enabled = False
Call chagestate
End If
End Sub
Public Sub chagestate()
If Shape1.Top <= 0 Or (Shape1.Top + Shape1.Height) >= Me.Height Then
degree = 2 * pi - degree
If Shape1.Top <= 0 Then Shape1.Top = 1
If (Shape1.Top + Shape1.Height) >= Me.Height Then Shape1.Top = Me.Height - Shape1.Height - 1
End If
If Shape1.Left <= 0 Or (Shape1.Left + Shape1.Width) >= Me.Width Then
If (Shape1.Left + Shape1.Width) >= Me.Width Then Shape1.Left = Me.Width - Shape1.Width - 1
If Shape1.Left <= 0 Then Shape1.Left = 1
If degree < pi / 2 Then degree = pi / 2 + degree
If degree > pi / 2 And degree < pi Then degree = 3 * pi / 2 - degree
If degree > pi Or degree < 2 * pi Then degree = 3 * pi - degree
End If
v = 150
Timer1.Enabled = True
End Sub
11
2024-11-15 广告
2024-11-15 广告
上海允若信息科技有限公司成立于2017年,是一家专注于电磁和等离子体仿真测试解决方案咨询、规划、定制开发和实施推广服务的专业化公司,允若意为:一允千金,上善若水。公司核心团队成员都毕业于国内外著名大学,在世界500强企业有多年工作经验。总部...
点击进入详情页
本回答由11提供
展开全部
在Form1上画一个image控件Image1和一个时钟控件Timer1,Image1的Stretch设置为True,picture属性里加载一个蛋蛋的图片~^ ^,Timer1的Interval属性设为1.
代码区里写下边的就行咯~
Dim l As Integer '记录水平运动状态
Dim t As Integer '记录垂直运动状态
Private Sub Timer1_Timer()
If Image1.Left >= Form1.ScaleWidth - Image1.Width Then l = 1 '移动到了最右边,变向向左
If Image1.Left <= 0 Then l = 0 '移动到了最左边,变向向右
If Image1.Top >= Form1.ScaleHeight - Image1.Height Then t = 1 '移动到了最底端,变向向上
If Image1.Top <= 0 Then t = 0 '移动到了最顶端,变向向下
If l = 0 Then
Image1.Left = Image1.Left + 10
Else
Image1.Left = Image1.Left - 10
End If
If t = 0 Then
Image1.Top = Image1.Top + 10
Else
Image1.Top = Image1.Top - 10
End If
End Sub
不知道这样你用不用的上~
代码区里写下边的就行咯~
Dim l As Integer '记录水平运动状态
Dim t As Integer '记录垂直运动状态
Private Sub Timer1_Timer()
If Image1.Left >= Form1.ScaleWidth - Image1.Width Then l = 1 '移动到了最右边,变向向左
If Image1.Left <= 0 Then l = 0 '移动到了最左边,变向向右
If Image1.Top >= Form1.ScaleHeight - Image1.Height Then t = 1 '移动到了最底端,变向向上
If Image1.Top <= 0 Then t = 0 '移动到了最顶端,变向向下
If l = 0 Then
Image1.Left = Image1.Left + 10
Else
Image1.Left = Image1.Left - 10
End If
If t = 0 Then
Image1.Top = Image1.Top + 10
Else
Image1.Top = Image1.Top - 10
End If
End Sub
不知道这样你用不用的上~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'一个Timer控件
'x0,y0为圆的坐标
'r1,r2为圆的横纵增量
Private Sub Timer1_Timer()
Static x0 As Integer, y0 As Integer, r1 As Integer, r2 As Integer
Me.Cls
x0 = x0 + r1
y0 = y0 + r2
If x0 > Me.ScaleWidth - 50 Then
r1 = -30
ElseIf x0 <= 50 Then
r1 = 30
End If
If y0 > Me.ScaleHeight - 50 Then
r2 = -30
ElseIf y0 <= 50 Then
r2 = 30
End If
Me.Circle (x0, y0), 100, vbBlue
End Sub
'祝你学习愉快。
'x0,y0为圆的坐标
'r1,r2为圆的横纵增量
Private Sub Timer1_Timer()
Static x0 As Integer, y0 As Integer, r1 As Integer, r2 As Integer
Me.Cls
x0 = x0 + r1
y0 = y0 + r2
If x0 > Me.ScaleWidth - 50 Then
r1 = -30
ElseIf x0 <= 50 Then
r1 = 30
End If
If y0 > Me.ScaleHeight - 50 Then
r2 = -30
ElseIf y0 <= 50 Then
r2 = 30
End If
Me.Circle (x0, y0), 100, vbBlue
End Sub
'祝你学习愉快。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询