动画:滑动和C#表单(winforms)上的淡入淡出控件

问题描述:

我正在尝试实现一种优雅地围绕(可能同时多个)控件进行动画化(翻译,淡入淡出)的方法.例如,假设我在左上角有一张图片,在右下角有一个文本框,我希望能够使它们在窗口上平滑滑动并切换位置.我已经工作了一段时间,但没有想出任何可以顺利或轻松实现此目标的方法.

I'm trying to implement a way to animate (translate, fade) controls around (more than one at the same time possibly) elegantly. For example, lets say I had a picture in the top left corner, and a textbox in the bottom right corner, I'd like to be able to have them smoothly slide across the window and switch places. I've been working for awhile but have not come up with anything that achieves this smoothly or easily.

查看 Github.在nuget上也可以使用dot-net-transitions.它支持各种线性/非线性过渡,包括复合过渡,可用于更复杂的效果,例如波纹.

Check out the dot-net-transitions project on Google Code. There's now a clone on Github here. It's also available on nuget as dot-net-transitions. It supports a variety of linear/non-linear transitions including composite transitions that can be used for more complex effects such as ripple.

以下是一个有效的示例,演示了您所需的行为:

Here is a working sample that demonstrates your desired behavior:

var pictureBox = new PictureBox
    {
        ImageLocation = "http://icons2.iconarchive.com/icons/klukeart/summer/128/hamburger-icon.png",
        SizeMode = PictureBoxSizeMode.AutoSize
    };
var textBox = new TextBox
    {
        Text = "Hello World",
        Location = new Point(140, 140)
    };
var form = new Form
    {
        Controls =
        {
            textBox,
            pictureBox
        }
    };
form.Click += (sender, e) =>
    {
        // swap the Left and Top properties using a transition
        var t = new Transition(new TransitionType_EaseInEaseOut(1000));
        t.add(pictureBox, "Left", textBox.Left);
        t.add(pictureBox, "Top", textBox.Top);
        t.add(textBox, "Left", pictureBox.Left);
        t.add(textBox, "Top", pictureBox.Top);
        t.run();
    };
form.ShowDialog();