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.
Slide animations are similar to transitions, but they are applied to individual elements on a single slide—a title, chart, image, or individual bullet point. Animations can make a presentation more lively and memorable.
How to add an animation: Open a presentation in Google Slides. Click the text or image you want to animate. Then click Insert > Animation. Click on Select an object to animate, scroll down and choose the animation you want to use.
There are four types of animation effects in PowerPoint – entrance, emphasis, exit and motion paths. These reflect the point at which you want the animation to occur.
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();
I recommend that you switch to WPF; that would make it far easier.
It is completely impossible to fade controls in WinForms; Windows controls cannot have opacity.
The closest you can get would be to render the control and its area on the form to a pair of bitmaps, then crossfade the bitmaps in a PictureBox using a ColorMatrix.
To slide controls in WinForms, you can use a Timer to gradually change the Top
and/or Left
properties of the controls and move them across the form. However, you'll get an annoying flicker, which is (AFAIK) impossible to remove.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With