[英]Color transition for C# .NET Framework?
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.所以我试图制作一个带有标题按钮的应用程序:“关闭、最小化、最大化/恢复”,但我似乎无法弄清楚如何将颜色的 R、G、B 值平滑地转换为另一个值。
I've gotten very good with Timers in C#, but I can't figure out how to calculate the values when transitioning.我对 C# 中的计时器非常熟悉,但我不知道如何在转换时计算值。
My code so far: (the close, minimize, etc 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.例如,您可以取当前时间并增加 1 秒。 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.对每个刻度重复此操作,即使某些刻度失败或最终重叠,您也应该始终按时达到最终颜色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.