0

I am making a UI for a friend and I want it to be unique(ish).

I want to make the background and text color transition in a loop upon start up.

What I have is:

public frmKaliUI()
    {
        InitializeComponent();

        colorFade1();
    }

    private async void colorFade1()
    {
        Color c = Color.FromArgb(139, 0, 139);

        for (int i = 255; i > 0; i--)
        {
            c = Color.FromArgb(139, i, 139);
            this.BackColor = c;

            await Task.Delay(50);
        }
    }

EDIT: Once "i" reaches 255 the for loop stops and the color does not transition. Is there a way to make this an infinite loop

mark11101
  • 1
  • 2
  • 2
    and the problem is? – Mohsen Kamrani Aug 07 '17 at 04:25
  • It only transictions from one color to the next then stops – mark11101 Aug 07 '17 at 04:27
  • 2
    use a `while (true)` and have `i++` modulo 255 – Gilad Green Aug 07 '17 at 04:39
  • i just added `if (i == 1) colorFade1();` after `await Task.Delay(50);` and it simply became an infinite loop! Though the transition doesn't looks good, i feel you should go with @GiladGreen suggestion – boop_the_snoot Aug 07 '17 at 04:41
  • Thanks, guys honestly was tumped forever – mark11101 Aug 07 '17 at 04:43
  • I don't see any evidence that you made any effort to actually modify your existing code to do what you want. You have a couple of typical options: use the `%` operator (see marked duplicate) to force the value back to the desired range; or check for out-of-range, and explicitly assign the value back to the other end of the range. The latter would probably be better in your case, since you are decrementing (the `%` operator will require special handling for the `-1` value you'll get after `0`) – Peter Duniho Aug 07 '17 at 04:44

0 Answers0