Hi Vanessa,
Please refer below sample.
I have added a Label and a Timer control in the Form.
Code
C#
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
}
private int _step = 10;
private void timer1_Tick(object sender, EventArgs e)
{
if (label1.Right > this.Width)
{
_step = -10;
}
if (label1.Left < 0)
{
_step = 10;
}
if (label1.Top > this.Height)
{
_step = -10;
}
if (label1.Bottom < 0)
{
_step = 10;
}
label1.Left += _step;
label1.Top += _step;
}
VB.Net
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
timer1.Start()
End Sub
Private _step As Integer = 10
Private Sub timer1_Tick(sender As Object, e As EventArgs) Handles timer1.Tick
If label1.Right > Me.Width Then
_step = -10
End If
If label1.Left < 0 Then
_step = 10
End If
If label1.Top > Me.Height Then
_step = -10
End If
If label1.Bottom < 0 Then
_step = 10
End If
label1.Left += _step
label1.Top += _step
End Sub
Screenshot