C# 淡入淡出闪屏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/84211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 11:23:41  来源:igfitidea点击:

Fade splash screen in and out

提问by Timothy Carter

In a C# windows forms application. I have a splash screen with some multi-threaded processes happening in the background. What I would like to do is when I display the splash screen initially, I would like to have it appear to "fade in". And then, once all the processes finish, I would like it to appear as though the splash screen is "fading out". I'm using C# and .NET 2.0. Thanks.

在 C# windows 窗体应用程序中。我有一个闪屏,其中有一些在后台发生的多线程进程。我想要做的是当我最初显示启动画面时,我想让它看起来“淡入”。然后,一旦所有过程完成,我希望它看起来好像启动屏幕正在“淡出”。我正在使用 C# 和 .NET 2.0。谢谢。

采纳答案by user7116

You could use a timer to modify the Form.Opacity level.

您可以使用计时器来修改Form.Opacity 级别

回答by RichS

You can use the Opacity property for the form to alter the fade (between 0.0 and 1.0).

您可以使用表单的 Opacity 属性来更改淡入淡出(在 0.0 和 1.0 之间)。

回答by Patrick Desjardins

While(this.Opacity !=0)
{
    this.Opacity -= 0.05;
    Thread.Sleep(50);//This is for the speed of the opacity... and will let the form redraw
}

回答by slyprid

When using Opacity property have to remember that its of type double, where 1.0 is complete opacity, and 0.0 is completely transparency.

使用 Opacity 属性时必须记住它的类型为 double,其中 1.0 是完全不透明度,0.0 是完全透明。

   private void fadeTimer_Tick(object sender, EventArgs e)
    {
        this.Opacity -= 0.01;

        if (this.Opacity <= 0)
        {
            this.Close();
        }            
    }