C # implement animation effects for your form

Source: Internet
Author: User

In WPF, you can easily implement the animation effect, but it is a little troublesome to implement it in a common winform program. Here I use a simulated method to implement winform-related animation.

Recall the implementation of the animation effect in WPF. first create a storyboard, then create an animation, and bind the property of the animation to the storyboard, finally, we get the desired effect. Here we only consider the linear change effect.

Here I mainly used to change the size and position of the control on winform to produce some animation effects.

Storyboard

To control the panel on the interface, You Need To asynchronously change some properties of the interface control. However, an animation effect requires a timer to cyclically execute and generate the animation effect. So first, use the start function to start a thread, and then enable a timer in thread sta () to execute related operations. Here I set the timer to be executed for 8 milliseconds at a time.

Timeint is a static variable used as a counter to determine the number of times the timer has been executed. When the execution is completed, it returns to zero. _ Control is the execution panel control passed in the constructor. It can be a form or control. Then let

_ Control. begininvoke (New sta (too ));

The notification page is changed. The Code is as follows:

 

 

The controlanimation loop in the last step is used to save the animation execution information.

This includes the animation effect. The property value of the control bound to the animation control is used in the too () function.

Propertyinfo value = TP. getproperty (A. Name );
If (value! = NULL)
{
Value. setvalue (A. Control, A. animation. Change (), null );
}

To assign values to attributes.

 

Finally, the animation is implemented, mainly to save the three values of the event time required by the starting value from the ending value to. After these three values are passed in, find the num to be changed, implement the change () value for each change,

The Code is as follows:

 

In this way, we can simply complete a class that simulates the animation effect: Let's look at the animationpoint class, which is only implemented using two animationint classes, of course, you can also use three to implement a color class...

Let's call it.

Let's see if I implemented a widget that moved 200 back and 200 to the position in 200 milliseconds. The effect is as follows:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.