Animations: Sliding & Fading controls on a C# form (winforms)

前端 未结 5 1184
甜味超标
甜味超标 2020-12-08 11:43

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

5条回答
  •  Happy的楠姐
    2020-12-08 12:06

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

提交回复
热议问题