C#win表单按钮颜色变化,以秒为单位 [英] C# win form button color change in seconds

查看:74
本文介绍了C#win表单按钮颜色变化,以秒为单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Win Form andi if if statment lIke

I am using Win Form andi have If statment lIke

<pre>If( a==0){
button6.back = Color.red;
}
else {
button6.back = Color.Green;



}

i也希望如果判断是真的它已经改变了像color.red然后color.white和反弹这种颜色延迟我使用计时器但它有点不工作任何人都可以帮助我如何我可以做到吗



我尝试过的事情:




}
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:

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;
        }

推荐答案

试试这个



负载方法

try this

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



计时器事件


timer event

private void timer1_Tick(object sender, EventArgs e)
       {
           if (a == 0)
           {
               button6.BackColor = Color.red;
           }
           else
           {
               button6.BackColor = Color.Green;
           }
       }


试试这个



try this

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;
       }


这篇关于C#win表单按钮颜色变化,以秒为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆