表单幻灯片转换C#

时间:2017-07-15 15:58:11

标签: c# winforms transition

我在Visual Studio中为我的表单创建转换, 我正在为宽度编码幻灯片效果,但最终会变慢 反正是为了让它更快? 顺便说一下这里是代码:

`int check = 0;
 private void button1_Click(object sender, EventArgs e)
    {
        this.button1.Text = "Hide";

        if (check == 0)
        {

            for (int i = 350; i <= 824; ++i)
            {
                this.Size = new Size(i, 507);
                Thread.Sleep(10);
                this.CenterToScreen();


            }
            check = 1;


        }

        else if (check == 1)
        {
            this.button1.Text = "Key";

            for (int i = 824; i >= 351; i--)
            {
                this.Size = new Size(i, 507);
                Thread.Sleep(5);
                this.CenterToScreen();


            }


            check = 0;

        }
    }

1 个答案:

答案 0 :(得分:1)

通过使用现有代码,您可以为了速度而调整它;

private int check = 0;
private void button1_Click(object sender, EventArgs e)
{
    this.button1.Text = "Hide";

    if (check == 0)
    {
        for (int i = 350; i <= 824; i += 2)
        {
            this.Size = new Size(i, 507);
            Thread.Sleep(1);
            this.CenterToScreen();
        }
        check = 1;


    }

    else if (check == 1)
    {
        this.button1.Text = "Key";

        for (int i = 824; i >= 351; i -= 2)
        {
            this.Size = new Size(i, 507);
            Thread.Sleep(1);
            this.CenterToScreen();
        }
        check = 0;
    }
}

您可以如上所述更改Thread.Sleep行,并增加或减少循环变量以加快动画效果。