vb.net物理小球 vb小球运动
在VB中如何使小球按照一定的轨迹运动
直线往复移动需要两个command,一个timer,一个lable控件timer的interval属性为1或自定义。折线和曲线需要自己定义方程式。
成都创新互联公司自2013年起,是专业互联网技术服务公司,拥有项目网站建设、网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元呼玛做网站,已为上家服务,为呼玛各地企业和个人服务,联系电话:028-86922220
Dim Step As Integer
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = flase
Timer1_Timer ' .改成_
End Sub
Private Sub Form_Load()
Step = 1
End Sub
Private Sub Timer1_Timer()
Label1.Move Label1.Left + 50 * Step
If Label1.Left + Label1.Width Form1.Width Then
Step = -1
ElseIf Label1.Left 0 Then '改成小于零
Step = 1
End If
End Sub
VB怎样实现一个小球碰壁反弹的效果?要简单点。还没有学复杂的函数。
假设高的移动速度为v1,横的移动速度为v2,小球的控件名为Ball
dim v1 as integer
dim v2 as integer
'下面为小球的移动
Ball.top=ball.top+v '向着右下移动
ball.left=ball.left+v
if ball.top=me.top then '撞击底部
v1=v1*-1 '重点:此处将高的移动速度乘以-1,表示让其反方向移动,下面同样
endif
if ball.left=me.left then '撞击右边
v2=v2*-1
endif
if ball.top=0 then '撞击顶部
v1=v1*-1
endif
if ball.left=0 then '撞击左边
v2=v2*-1
endif
这是最基本的反弹效果,可以根据你的需要做适当更改
VB要求在窗体上一小球(shape1)从左到右移动,到右边界后反向移动,如此往复
'窗体加一个timer1
Dim x As Boolean
Private Sub Form_Load()
Timer1.Interval = 50
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer() '
If x Then
Shape1.Left = Shape1.Left - 100
Else
Shape1.Left = Shape1.Left + 100
End If
If Shape1.Left = Me.ScaleWidth - Shape1.Width Then
x = True
ElseIf Shape1.Left = 0 Then
x = False
End If
End Sub
用vb.net编写项目移动。。。求高人指点。。。。
窗体是指由两个列表框(ListBox1、ListBox2)和4个命令按钮(Button1“”按钮,Button2“”按钮,Button3“”按钮,Button4“”按钮)所构成的界面,代码:
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.Text = "选项移动"
ListBox1.SelectionMode = SelectionMode.MultiSimple
ListBox2.SelectionMode = SelectionMode.One
For i = 1 To 10
ListBox1.Items.Add(Chr(Asc("a") + i - 1))
Next
For i = 1 To 10
ListBox2.Items.Add(i.ToString)
Next
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If ListBox1.SelectedItems Is Nothing Then Exit Sub
Dim b As ListBox.ObjectCollection
For i = 0 To Me.ListBox1.SelectedItems.Count - 1
Me.ListBox2.Items.Add(Me.ListBox1.SelectedItems(0))
Me.ListBox1.Items.RemoveAt(Me.ListBox1.SelectedIndices(0))
Next
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
If ListBox2.SelectedItems IsNot Nothing Then
ListBox1.Items.Add(ListBox2.SelectedItem)
ListBox2.Items.Remove(ListBox2.SelectedItem)
End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
For Each itm As Object In ListBox1.Items
ListBox2.Items.Add(itm)
Next
ListBox1.Items.Clear()
End Sub
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
For Each itm As Object In ListBox2.Items
ListBox1.Items.Add(itm)
Next
ListBox2.Items.Clear()
End Sub
End Class
分享标题:vb.net物理小球 vb小球运动
文章源于:http://scyanting.com/article/dodgpdp.html