Hi satabeach,
Use TimerControl. Refer below example.
Code
C#
public partial class Form1 : Form
{
private static int LoopCount;
private static DataTable dt;
private static Timer timer1;
private Label lblName;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
LoopCount = 0;
dt = new DataTable();
dt.Columns.Add("Name");
dt.Rows.Add("Apple");
dt.Rows.Add("Mango");
dt.Rows.Add("Banana");
dt.Rows.Add("Orange");
lblName = new Label();
this.Controls.Add(lblName);
timer1 = new Timer();
timer1.Interval = 2000;
timer1.Tick += new EventHandler(OnTick);
timer1.Enabled = true;
}
private void OnTick(object source, EventArgs e)
{
if (LoopCount < dt.Rows.Count)
{
lblName.Text = dt.Rows[LoopCount]["Name"].ToString();
LoopCount++;
}
else
{
LoopCount = 0;
lblName.Text = dt.Rows[LoopCount]["Name"].ToString();
LoopCount++;
}
}
}
VB.Net
Public Class Form1
Private Shared LoopCount As Integer
Private Shared dt As DataTable
Private Shared timer1 As Timer
Private Shared lblName As Label
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LoopCount = 0
dt = New DataTable()
dt.Columns.Add("Name")
dt.Rows.Add("Apple")
dt.Rows.Add("Mango")
dt.Rows.Add("Banana")
dt.Rows.Add("Orange")
lblName = New Label()
Me.Controls.Add(lblName)
timer1 = New Timer()
timer1.Interval = 2000
AddHandler timer1.Tick, AddressOf OnTick
timer1.Enabled = True
End Sub
Private Sub OnTick(ByVal source As Object, ByVal e As EventArgs)
If LoopCount < dt.Rows.Count Then
lblName.Text = dt.Rows(LoopCount)("Name").ToString()
LoopCount += 1
Else
LoopCount = 0
lblName.Text = dt.Rows(LoopCount)("Name").ToString()
LoopCount += 1
End If
End Sub
End Class
Screenshot