动画:滑动和C#表单(winforms)上的淡入淡出控件 [英] Animations: Sliding & Fading controls on a C# form (winforms)

查看:411
本文介绍了动画:滑动和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.

推荐答案

查看

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();

这篇关于动画:滑动和C#表单(winforms)上的淡入淡出控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆