So I'm trying to make an app with caption buttons: "close, minimize, maximize/restore", but I can't seem to figure out how to transition the R,G,B values of the color to another one smoothly.
I've gotten very good with Timers in C#, but I can't figure out how to calculate the values when transitioning.
My code so far: (the close, minimize, e.t.c stuffs are pre-made rectangles)
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
var pos = e.Location;
if (close.Contains(pos))
{
Timer t = new Timer { Interval = 1 };
t.Tick += delegate (object sender_, EventArgs e_)
{
// transition here
};
t.Start();
}
if (!close.Contains(pos))
{
Timer t = new Timer { Interval = 1 };
t.Tick += delegate (object sender_, EventArgs e_)
{
// "reverse" code here
};
t.Start();
}
}
NOTE: I AM NOT ASKING FOR AN ENTIRE CODE SNIPPET, just some mathematical solutions so I can do this easily.
When the button is clicked, compute the time at which you wish the transition to complete. For example, you might take the current time and add 1 second. Store this value.
When the timer tick fires, perform these steps:
Repeat this for each tick and you should always hit the final color right on time, even if some of the ticks fail or end up overlapping.