Find the red, green, and blue values of both colors. You will need 6
variables, one for each start, and one for each destination value of each
color. Determine the length of time for the fade. Use a timer to change
the values. Set the timer interval to a fraction of a second (say, for
example, 1/10th of a second, or 100 milliseconds) , and calculate the
number of intervals you need to complete the change in the time you
specify. For example, if you want the change to occur over a period of 3
seconds, and your interval is 100 milliseconds, the number of intervals
will be 30.
You want each color to change at the same rate, so as the difference
between each of the 3 start and destination values will differ, you will
need to calculate the difference for each start and destination value, and
divide that by the total number of intervals between the start and end of
the fade. This will yield the number that each value should change. It
must be a float or a double in order to be accurate, so you will need to
convert it to an integer after the calculation.
With each elapsed event of the timer, change the values of all 3 and
create a Color structure from the 3 values. Set the background color of
the Control to that color.
Since you are rounding, you will want to check and make sure that the
values don't go beyond the target values, or fall short of the target
values. This may require a bit of tweaking along the way, by redoing the
calculation at each event, or possibly by stopping a bit early on any
given value (when it reaches the destination), or adjusting it at the end
to catch up with the destination.
That's it in a nutshell.
--
HTH,
Kevin Spencer
Microsoft MVP
Professional Numbskull
Show me your certification without works,
and I'll show my certification
*by* my works.