AnimatedImageManager.SuspendAnimation(this.imageInstance);
This topic provides information on the Animated GIF Support in Ultimate UI for Windows Forms controls.
The following topics are prerequisites to understanding this topic:
This topic contains the following sections:
In addition to the pre-existing static image support, our Presentation Layer Framework (PLF) now has the ability to display animated images throughout our components. A new AnimatedImageManager class has been added to the framework to automatically handle the rendering of images containing time-based frames.
The AnimatedImageManager is a static manager responsible for managing animated images within our Presentation Layer Framework. The primary function of the manager is to keep track of all animated images within our components while exposing the ability to suspend and resume animation on specific Image instances.
The SuspendAnimation() method should be used whenever animation should be halted on all registered images or a specified instance of an image. Once suspended, an image will be rendered using only its current frame.
The following code snippets demonstrates how to suspend the animation on single Image instance.
In C#:
AnimatedImageManager.SuspendAnimation(this.imageInstance);
In Visual Basic:
AnimatedImageManager.SuspendAnimation(Me.imageInstance)
After having animation previously suspended, the ResumeAnimation() method can be used to restart animation on all suspended images (or a specified instance of an image) starting at the current frame.
The following code snippets demonstrates how to resume the animation on single Image instance.
In C#:
AnimatedImageManager.ResumeAnimation(this.imageInstance);
In Visual Basic:
AnimatedImageManager.ResumeAnimation(Me.imageInstance)
Whenever the current frame of an animated image changes, the AnimatedImageManager fires an ImageFrameChanged event to notify all listeners of the frame change. The ImageFrameChangedEventArgs for this event exposes the Image, the index of the current frame, and the total number of time-based frames in the image. It also exposes a SuspendAnimation property which allows the animation on the image to be suspended from within the event handler.
In C#:
// Subscribe to the ImageFrameChanged event (currently in the Form's Load event handler) AnimatedImageManager.ImageFrameChanged += AnimatedImageManager_ImageFrameChanged; // ImageFrameChanged event handler void AnimatedImageManager_ImageFrameChanged(object sender, AnimatedImageManager.ImageFrameChangedEventArgs e) { // if this is the last frame of the image, and it is the UltraButton's Image, // suspend the animation (or unassign the Image from the Appearance). if (e.IsLastFrame && e.Image == this.ultraButton1.Appearance.Image) { e.SuspendAnimation = true; } }
In Visual Basic:
' Subscribe to the ImageFrameChanged event (currently in the Form's Load event handler) AddHandler AnimatedImageManager.ImageFrameChanged, AddressOf AnimatedImageManager_ImageFrameChanged 'Image FrameChanged event handler Private Sub AnimatedImageManager_ImageFrameChanged(sender As Object, e As AnimatedImageManager.ImageFrameChangedEventArgs) ' if this is the last frame of the image, and it is the UltraButton's Image, ' suspend the animation (or unassign the Image from the Appearance). If e.IsLastFrame AndAlso e.Image Is Me.UltraButton1.Appearance.Image Then e.SuspendAnimation = True End If End Sub
In some scenarios, such as when image animation has been implemented externally to our framework, it may be necessary to turn off image animation within the PLF. This can be done via the AnimatedImageManager’s Enabled property.
In C#:
AnimatedImageManager.Enabled = false;
In Visual Basic:
AnimatedImageManager.Enabled = false
Due to the design of Window Forms, whenever the frame of an image changes, it is necessary to invalidate the portion of the control where the image is rendered. As such, using very large or a large number of animated images simultaneously will most likely result in an increase in CPU utilization.
The AnimatedImageManager keeps track of when an Image has had its animation suspended (without regards to whether or not the image is being utilized by one of our controls). This allows for the suspension of animation prior to the initial rendering of an image. However, if a currently suspended image is no longer being used by a control, it is recommended to resume the animation on the image, so the AnimatedImageManager will no longer need to keep track of the image, and will release the image from memory.
The following topics provide additional information related to this topic: