本文介绍了“错误CS1513:}预期”在我的“Form1.cs”中救命! :(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有一个非常大的问题,这让我烦恼,似乎只需要一个简单的改变,但我不知道是什么!我正在使用Visual Studio 2010.



这是我的代码:



Hello, I am having a really big problem that is bugging me, and it seems like it only needs a simple change, but I don't know what! I am using Visual Studio 2010.

Here is my code:

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
    if(checkBox1.Checked)
    {
        FlashingName = true;
        timer1.Enabled = true;
        timer1.Start();
    }
    else

        FlashingName = false;
        timer1.Enabled = false;
        timer1.Stop();

    }







问题是最后一个}。




The problem is the very last "}".

推荐答案

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
    if(checkBox1.Checked)
    {
        FlashingName = true;
        timer1.Enabled = true;
        timer1.Start();
    }
    else
    {   // add this bracket
        FlashingName = false;
        timer1.Enabled = false;
        timer1.Stop();
 
    }
} // also add this bracket







顺便说一下, timer1.Enabled = true; timer1.Start(); timer1.Enabled = false; 相同与 timer1.Stop();

相同所以你可以通过写这个来简单地优化你的代码:




By the way, timer1.Enabled = true; does the same as timer1.Start(); and timer1.Enabled = false; does the same as timer1.Stop();
So you can simply optimize your code by writing this:

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
    FlashingName = checkBox1.Checked;
    timer1.Enabled = checkBox1.Checked;
}



如果 checkBox1.Checked true ,然后 FlashingName timer1.Enabled true 也。如果 checkBox1.Checked false tiemr1.Enabled FlashingName false


If checkBox1.Checked is true, then FlashingName and timer1.Enabled will be true also. Same if checkBox1.Checked is false: tiemr1.Enabled and FlashingName will be false


private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
    if(checkBox1.Checked)
    {
        FlashingName = true;
        timer1.Enabled = true;
        timer1.Start();
    }
    else
    {
        FlashingName = false;
        timer1.Enabled = false;
        timer1.Stop();
    }
}


private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                FlashingName = true;
                timer1.Enabled = true;
                timer1.Start();
            }
            else
            {
                FlashingName = false;
                timer1.Enabled = false;
                timer1.Stop();

            }
        }
    }
}


这篇关于“错误CS1513:}预期”在我的“Form1.cs”中救命! :(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 23:02