简体   繁体   English

我将如何制作按钮 go flash?

[英]How would I go about making buttons flash?

I'm making a application for playing Connect4.我正在制作一个玩 Connect4 的应用程序。 I wanted to indicate the players turn more clearly by having the clickable buttons flash the color of the players turn.我想通过让可点击按钮 flash 显示球员转身的颜色来更清楚地指示球员转身。 I was wondering how I would go about doing that.我想知道我将如何 go 这样做。 Sorry if this has been answered before, if so can you please link me to the post.抱歉,如果之前已经回答过这个问题,如果可以的话,请将我链接到该帖子。

bgwMain = new BackgroundWorker();
bgwMain.WorkerSupportsCancellation = true;

int Red;
int Green;
int Blue;

bgwMain.DoWork += ;

while (!mre.WaitOne())
{
    for (int i = 0; i != 255; i++)
    {
        Red = i;
        Green = i;

        for (int z = 42; z <= btnLongArray.Length - 1; z++)
        {
            btnLongArray[z].BackColor = Color.FromArgb(Red, Green, 0);
        }

        if (i == 255)
        {
            for (int x = 255; x != 0; x--)
            {
                Red = x;
                Green = x;

                for (int z = 42; z <= btnLongArray.Length - 1; z++)
                {
                    btnLongArray[z].BackColor = Color.FromArgb(Red, Green, 0);
                }
            }
        }
    }
}

I have a good grasp of event driven programming and I'm pretty sure this would require some sort of event checker or background worker.我很好地掌握了事件驱动编程,我很确定这需要某种事件检查器或后台工作者。 I'm not sure how to go about making this work.我不确定如何 go 使这项工作。 My current error is on the while loop ".mre.waitone" and "bgwMain;DoWork +=.."Not to sure what I was trying to do with this as it's been a while since I last opened this project, I believe I was trying to call a Manual Reset Event Class, either way.我当前的错误是在 while 循环“.mre.waitone”和“bgwMain;DoWork +=..”中,我不确定我试图用这个做什么,因为自从我上次打开这个项目以来已经有一段时间了,我相信我无论哪种方式,都试图调用手动重置事件 Class。 I'm not to sure, Please let me know how I should go about making this happen, thanks in advance!我不确定,请让我知道我应该如何做到这一点 go,在此先感谢!

// Keeps track of the number of blinks
private int m_nBlinkCount = 0;

// ...

// tmrTimer is a component added to the form.
tmrTimer.Tick += new EventHandler(OnTimerTick);

m_nBlinkCount = 0;
tmrTimer.Interval = 1000; // 1 second interval
tmrTimer.Start();

// In Tick event, keep changing the background color of your button

private void OnTimerTick ( Object sender, EventArgs eventargs)
{
    if (btnLongArray.BackColor == Color.Red)
        btnLongArray.BackColor = Color.Transparent;
    else
        btnLongArray.BackColor = Color.Red;

    m_nBlinkCount++;

    if ( m_nBlinkCount >= 10 )
        tmrTimer.Stop ();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM