简体   繁体   English

显示表格后减少表格的不透明度

[英]Decrease Form Opacity after Form is shown

I want to make it short: This is what I want to archieve WITHOUT clicking any buttons. 我想简短地说: 是我要存档的内容,而无需单击任何按钮。 When I change the opactiy in Form1_Load or Form1_Shown the application will NOT be shown to the user until my code finishes its thing. 当我在Form1_LoadForm1_Shown更改Opactiy时,在我的代码完成其操作之前,该应用程序将不会显示给用户。
Thats the code 那就是代码

for (int i = 0; i < 100; i++)
{
    this.Opacity -= .05;
    System.Threading.Thread.Sleep(50);
}

Can anyone tell me how to archieve my goal? 谁能告诉我如何实现我的目标?

private async void FadeIn(Form o, int interval = 80) 
{
    //Object is not fully invisible. Fade it in
    while (o.Opacity < 1.0)
    {
        await Task.Delay(interval);
        o.Opacity += 0.05;
    }
    o.Opacity = 1; //make fully visible       
}

private async void FadeOut(Form o, int interval = 80)
{
    //Object is fully visible. Fade it out
    while (o.Opacity > 0.0)
    {
        await Task.Delay(interval);
        o.Opacity -= 0.05;
    }
    o.Opacity = 0; //make fully invisible       
}

This what I found on Stackoverflow for you. 这就是我在Stackoverflow上为您找到的。 Use those methods Form1_Load. 使用那些方法Form1_Load。 The issue I assume you had what that you used sync methods, which must be finished before programm contineus with next fragment of code. 我认为您有使用同步方法的问题,必须在同步下一个代码片段之前完成同步方法。 Thats why windows was not showned to you before code application loaded. 这就是为什么在加载代码应用程序之前未向您显示Windows的原因。

Code from : Better algorithm to fade a winform 来自的代码: 更好的算法来淡化Winform

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

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