Hi anirudhp,
You can't display blinking on same panel.
For this you need to add another panel where you will display the blinking effect.
Refer below code.
I have added two panels in the form.
C#
private void Form1_Load(object sender, EventArgs e)
{
panel1.BackColor = Color.Red;
System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
if (panel1.BackColor == Color.Red)
{
timer1.Start();
System.Threading.Thread thread = new System.Threading.Thread(Blink);
thread.Start();
}
}
int count = 10;
private void Blink(object o)
{
bool go = false;
while (count > 0)
{
while (!go)
{
panel2.BackColor = Color.Red;
go = true;
System.Threading.Thread.Sleep(500);
}
while (go)
{
panel2.BackColor = Color.Green;
go = false;
System.Threading.Thread.Sleep(500);
}
}
}
}
VB.Net
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
panel1.BackColor = Color.Red
Dim timer1 As System.Windows.Forms.Timer = New System.Windows.Forms.Timer()
If panel1.BackColor = Color.Red Then
timer1.Start()
Dim thread As System.Threading.Thread = New System.Threading.Thread(AddressOf Blink)
thread.Start()
End If
End Sub
Private count As Integer = 10
Private Sub Blink(ByVal o As Object)
Dim go As Boolean = False
While count > 0
While Not go
panel2.BackColor = Color.Red
go = True
System.Threading.Thread.Sleep(500)
End While
While go
panel2.BackColor = Color.Green
go = False
System.Threading.Thread.Sleep(500)
End While
End While
End Sub
Screenshot