帮忙做个VB程序代码作业!
- 提问者网友:兔牙战士
- 2021-07-20 12:20
- 五星知识达人网友:污到你湿
- 2021-07-20 13:07
添加个窗体,加个TIMER控件,复制一下代码,2个问题都处理了
Private Sub Form_Load()
Label1.Caption = "求学到渝工,事业必成功"
Label1.Left = Me.Width
Label2.Left = Me.Width
Label2.Top = Me.Height
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
If Label1.Left <= Me.Width Then Label1.Left = Label1.Left - 100
If Label1.Left <= -Label1.Width Then Label1.Left = Me.Width
If Label2.Left <= Me.Width Then Label2.Left = Label2.Left - 100
If Label2.Left <= -Label2.Width Then Label2.Left = Me.Width
If Label2.Top >= 0 Then Label2.Top = Label2.Top - 80
If Label2.Top <= 0 Then Label2.Top = Me.Height
End Sub
- 1楼网友:天凉才是好个秋
- 2021-07-20 16:39
帮人做作业是不对的,不过你是大学生,就帮你一次吧。
建一个VB窗口,名字叫form1,然后将下面的代码粘贴到代码区就OK了,运行后会有3种跑动效果。
Dim WithEvents myLAB As Label Dim WithEvents myTIM As Timer Dim byRun As Boolean Dim runType As Integer Private Sub Form_Load() byRun = False runType = 0 Set myLAB = Controls.Add("VB.Label", "myLAB") Set myTIM = Controls.Add("VB.Timer", "myTIM") myLAB.AutoSize = True myLAB.Caption = "求学到渝工,事业必成功" myLAB.Top = Form1.Height / 2 myLAB.Left = Form1.Width / 2 myLAB.Visible = True myTIM.Enabled = True myTIM.Interval = 10 End Sub
Private Sub myTIM_Timer() If byRun = False Then Randomize (Timer) runType = Rnd(Timer) * 100 Mod 3 byRun = True Select Case runType Case 0 myLAB.Left = Me.Width Randomize (Timer) myLAB.Top = Rnd(Timer) * 1000000 Mod Me.Height Case 1 myLAB.Top = Me.Height Randomize (Timer) myLAB.Left = Rnd(Timer) * 1000000 Mod Me.Width Case 2 myLAB.Left = Me.Width myLAB.Top = Me.Height End Select Else Dim speedivt As Integer speedivt = 10 '速度因子,越大速度越快,但会产生更大的跳动感 Select Case runType Case 0 If myLAB.Left > 0 - myLAB.Width Then myLAB.Left = myLAB.Left - speedivt Else byRun = False End If Case 1 If myLAB.Top > 0 - myLAB.Height Then myLAB.Top = myLAB.Top - speedivt Else byRun = False End If Case 2 If (myLAB.Left > 0 - myLAB.Width) And (myLAB.Top > 0 - myLAB.Height) Then myLAB.Left = myLAB.Left - speedivt myLAB.Top = myLAB.Top - speedivt Else byRun = False End If End Select End If End Sub
- 2楼网友:孤老序
- 2021-07-20 15:51
添加个窗体,加个TIMER控件,复制一下代码,2个问题都处理了
Private Sub Form_Load() Label1.Caption = "求学到渝工,事业必成功" Label1.Left = Me.Width Label2.Left = Me.Width Label2.Top = Me.Height Timer1.Interval = 100 End Sub
Private Sub Timer1_Timer() If Label1.Left <= Me.Width Then Label1.Left = Label1.Left - 100 If Label1.Left <= -Label1.Width Then Label1.Left = Me.Width
If Label2.Left <= Me.Width Then Label2.Left = Label2.Left - 100 If Label2.Left <= -Label2.Width Then Label2.Left = Me.Width
If Label2.Top >= 0 Then Label2.Top = Label2.Top - 80
If Label2.Top <= 0 Then Label2.Top = Me.Height End Sub
- 3楼网友:英雄的欲望
- 2021-07-20 14:39
提醒你下很简单利用坐标和循环语句就可以实现
我现在上课没时间帮忙瞎逛逛- -!
设置成一个死循环他就会一直动了
- 4楼网友:第四晚心情
- 2021-07-20 14:24
从右向左的代码如下:
添加一个label1和timer
Private Sub Form_Load() Label1.Caption = "求学到渝工,事业必成功" Label1.Left = Me.Width Timer1.Interval = 100 End Sub Private Sub Timer1_Timer() If Label1.Left <= Me.Width Then Label1.Left = Label1.Left - 100 If Label1.Left <= -Label1.Width Then Label1.Left = Me.Width End Sub