Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using Win Form andi have If statment lIke
C#
<pre>If( a==0){
button6.back = Color.red;
}
else {
button6.back = Color.Green;

}
i want too when if statment is true it has changed like color.red then color.white and bounce on this colors with delay i use timer but it is kinda not working can anyone help mee how can i make it

What I have tried:

C#
timer1.interval = 30;

If( a==0){
timer1.start();
button6.back = Color.red;
}
else {
button6.back = Color.Green;
    private void timer1_Tick(object sender, EventArgs e)
        {

           
button6.back = Color.White;
        }
Posted
Updated 26-Jun-16 23:00pm
Comments
BillWoodruff 27-Jun-16 4:11am    
Your question is not clear. At what point do you (ever) stop the Timer ? Do you want the Control to change BackColor every time the Timer 'Tick Event occurs ?
GTR0123 27-Jun-16 4:34am    
i have tryed with timer but if it is possible without timer it will be good like button color switch i want fast time
Simon_Whale 27-Jun-16 4:42am    
How is "a" variable set?
GTR0123 27-Jun-16 4:47am    
a is int veriable it is getin 0 or 1 value i want to make button color switching like a signal https://upload.wikimedia.org/wikipedia/commons/6/68/Obstruction_warning_indicator-2.gif
like this look itis switching color every second i want to make like that :/

try this

On Load Method
button6.BackColor = Color.White;
timer1.interval = 30;
timer1.start();

timer event
C#
private void timer1_Tick(object sender, EventArgs e)
       {
           if (a == 0)
           {
               button6.BackColor = Color.red;
           }
           else
           {
               button6.BackColor = Color.Green;
           }
       }
 
Share this answer
 
Comments
GTR0123 27-Jun-16 4:39am    
doesn't works for me :/
KishanNPatel 27-Jun-16 8:45am    
try this

private void timer1_Tick(object sender, EventArgs e)
{
if (a == 0)
{
button6.BackColor = Color.red;
a=1;
}
else
{
button6.BackColor = Color.Green;
a = 0;
}
}
GTR0123 28-Jun-16 4:49am    
kinde not that :/ https://upload.wikimedia.org/wikipedia/commons/6/68/Obstruction_warning_indicator-2.gif
like this
KishanNPatel 28-Jun-16 9:38am    
http://ge.tt/76yFGvb2

get this code and give a try..
try this

C#
private void Form1_Load(object sender, EventArgs e)
       {
           System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
           myTimer.Interval = 500; // milli seconds
           myTimer.Tick += myTimer_Tick;


           int a = 0;
           if (a == 0)
           {
               myTimer.Start();
               button6.BackColor = Color.Red;
           }
           else
           {
               button6.BackColor = Color.Green;

           }
       }

       void myTimer_Tick(object sender, EventArgs e)
       {
           button6.BackColor = Color.White;
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900