Option Explicit '直接F5:) Private Const lDir As Long = -1 '方向,+1与-1分别为右转与左转 Dim WithEvents Timer1 As TimerPrivate Sub Form_Load()'用代码添加控件并设置控件的初始状态. '这样方便点,可以直接粘贴+F5:)With Me.Controls.Add "VB.Label", "Label1".Add "VB.Label", "Label2".Add "VB.PictureBox", "Picture1".Add "VB.Timer", "Timer2"Set Timer1 = Me!Timer2End WithWith Me!Label1.AutoSize = True.Caption = "<-- 测试测试!@$)(#*%#^*$#@! -->".Visible = TrueMe!Label2.Visible = TrueEnd WithWith Me!Picture1.Appearance = 0 'Flat.Move 1000, 1000, Me!Label1.Width, Me!Label1.Height + 30.Visible = TrueEnd WithWith Me!Label1Set .Container = Me!Picture1Set Me!Label2.Container = Me!Picture1.Move 0, 0Me!Label2.Move .Width, 0, .Width, .HeightMe!Label2.Caption = .CaptionEnd WithTimer1.Interval = 50Timer1.Enabled = True End SubPrivate Sub Timer1_Timer()Static oLab1 As Label, oLab2 As LabelDim oTmp As LabelIf oLab1 Is Nothing Then Set oLab1 = Me!Label1If oLab2 Is Nothing Then Set oLab2 = Me!Label2If lDir > 0 ThenIf oLab1.Left > oLab1.Width ThenSet oTmp = oLab1Set oLab1 = oLab2Set oLab2 = oTmpEnd IfElseIf oLab1.Left <= -oLab1.Width ThenSet oTmp = oLab1Set oLab1 = oLab2Set oLab2 = oTmpEnd IfEnd IfWith oLab1.Move .Left + 15 * lDiroLab2.Move .Left + .Width * (-lDir)Me.Caption = .Left & "," & oLab2.LeftEnd WithDoEvents End Sub
转载于:https://www.cnblogs.com/any-time-any-place/archive/2012/11/08/2759832.html