0

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.
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?

diiN__________
  • 7,393
  • 6
  • 42
  • 69
  • Hmm, no, that effect is applied to the splash screen when it closes, not when the main window opens. Its FormClosing event for example. Start the Opacity at 99 so it won't flicker. You need a splash screen first. – Hans Passant Nov 04 '16 at 13:57

1 Answers1

1
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. Use those methods 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.

Code from : Better algorithm to fade a winform

Community
  • 1
  • 1
Demon
  • 379
  • 2
  • 7
  • You got the answer from [here](http://stackoverflow.com/questions/12497826/better-algorithm-to-fade-a-winform). Please add the source when copying from another post. – diiN__________ Nov 04 '16 at 13:59