'单位采用pix Const speed = 2'速度 Dim f'用来判断方向Private Sub Timer1_Timer() If Label1.Left > Form1.ScaleWidth - Label1.Width Then f = 2 ElseIf (Label1.Left < 0) Then f = 1 End IfIf f = 2 Then Label1.Left = Label1.Left - speed Else Label1.Left = Label1.Left + speed End IfEnd Sub
Option Explicit Dim fx As Integer 'labelÒƶ¯µÄ·½Ïò 1 Ϊ´Ó×óµÀÓÒ '£­1 Ϊ´ÓÓÒµÀ×óPrivate Sub command1_Click() If Command1.Caption = "Òƶ¯" Then Command1.Caption = "Í£Ö¹" Else Command1.Caption = "Òƶ¯" End If
Timer1.Enabled = Not (Timer1.Enabled)
End SubPrivate Sub Form_Load() Command1.Caption = "Òƶ¯" Timer1.Enabled = False Timer1.Interval = 100 fx = 1 End SubPrivate Sub Timer1_Timer()
With Label1 If .Left > ScaleWidth - .Width Or .Left < 0 Then fx = -1 * fx
Randomize
Timer1.Interval = 1000
End SubPrivate Sub Timer1_Timer()
Dim int_i, int_j As Integer int_i = Rnd() * Me.Width
int_j = Rnd() * Me.Height
Label1.Left = int_i
Label1.Top = int_jEnd Sub
楼主是要来回走动找个教 movingtext.ocx 的控件可以实现文字的来回走动
我用的就是这个啊
Const speed = 2'速度
Dim f'用来判断方向Private Sub Timer1_Timer()
If Label1.Left > Form1.ScaleWidth - Label1.Width Then
f = 2
ElseIf (Label1.Left < 0) Then
f = 1
End IfIf f = 2 Then
Label1.Left = Label1.Left - speed
Else
Label1.Left = Label1.Left + speed
End IfEnd Sub
Dim fx As Integer 'labelÒƶ¯µÄ·½Ïò 1 Ϊ´Ó×óµÀÓÒ
'£­1 Ϊ´ÓÓÒµÀ×óPrivate Sub command1_Click() If Command1.Caption = "Òƶ¯" Then
Command1.Caption = "Í£Ö¹"
Else
Command1.Caption = "Òƶ¯"
End If
Timer1.Enabled = Not (Timer1.Enabled)
End SubPrivate Sub Form_Load()
Command1.Caption = "Òƶ¯"
Timer1.Enabled = False
Timer1.Interval = 100
fx = 1
End SubPrivate Sub Timer1_Timer()
With Label1
If .Left > ScaleWidth - .Width Or .Left < 0 Then
fx = -1 * fx
End If
Label1.Move Label1.Left + fx * 100
End With
End Sub