> For the complete documentation index, see [llms.txt](https://docs-siticoneframework.gitbook.io/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-siticoneframework.gitbook.io/home/net-framework-or-net-core-ui/progress-and-loading/siticone-hbarsprogress/animation-control.md).

# Animation Control

Animation Control provides animated transitions between progress values using configurable timing, easing functions, and state notifications.

## Overview

The Animation Control feature in the `SiticoneHBarsProgress` component enables smooth transitions when updating the progress value. Developers can customize the duration, easing style, and observe animation state changes through dedicated properties and events. This documentation covers all aspects of the animation functionality, including configuration properties, events, methods, usage examples, best practices, and common pitfalls.

***

### API Reference

| Feature Element       | Type            | Default Value  | Description                                                                                                                                                    |
| --------------------- | --------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| AnimationDuration     | Property (int)  | 250 ms         | Sets the duration (in milliseconds) for the progress animation transition; values below 16 ms are clamped to a minimum duration.                               |
| AnimationEnabled      | Property (bool) | true           | Enables or disables the animated transition when the progress value changes.                                                                                   |
| AnimationEasingFunc   | Property (enum) | EaseInOutCubic | Determines the easing function used during the animation (options: Linear, EaseInQuad, EaseOutQuad, EaseInOutQuad, EaseInCubic, EaseOutCubic, EaseInOutCubic). |
| IsAnimating           | Property (bool) | false          | Read-only property that indicates whether an animation is currently in progress.                                                                               |
| AnimationCompleted    | Event           | N/A            | Triggered when the current animation completes.                                                                                                                |
| AnimationStateChanged | Event           | N/A            | Raised when the animation state changes (i.e., when animation starts or stops).                                                                                |
| StopAnimation()       | Method          | N/A            | Immediately stops any ongoing animation and sets the progress bar to the target value.                                                                         |

***

### Code Examples

#### Example 1: Basic Animation Configuration

This example demonstrates how to configure the animation properties for the progress bar and handle animation events.

```csharp
// Create an instance of the progress bar control.
var progressBar = new SiticoneHBarsProgress();

// Set the animation duration to 500 milliseconds.
progressBar.AnimationDuration = 500;

// Set the easing function to EaseOutQuad.
progressBar.AnimationEasingFunc = SiticoneHBarsProgress.AnimationEasing.EaseOutQuad;

// Enable animation.
progressBar.AnimationEnabled = true;

// Subscribe to the AnimationCompleted event.
progressBar.AnimationCompleted += (sender, args) =>
{
    MessageBox.Show("Animation completed!");
};

// Subscribe to the AnimationStateChanged event.
progressBar.AnimationStateChanged += (sender, e) =>
{
    Console.WriteLine($"IsAnimating: {e.IsAnimating}");
};

// Change the progress value to trigger animation.
progressBar.Value = 80;
```

#### Example 2: Stopping an Ongoing Animation

This sample demonstrates how to immediately stop an animation and update the progress value without animation.

```csharp
// Suppose an animation is in progress.
if (progressBar.IsAnimating)
{
    // Stop the current animation.
    progressBar.StopAnimation();
}

// Update the progress value without animation.
progressBar.SetValueWithoutAnimation(50);
```

#### Example 3: Dynamic Animation Settings Based on User Input

In this example, a user interface (e.g., a button click) dynamically alters the animation properties.

```csharp
private void btnUpdateAnimation_Click(object sender, EventArgs e)
{
    // Toggle animation enabled state.
    progressBar.AnimationEnabled = !progressBar.AnimationEnabled;

    // Update animation duration based on a slider control value.
    progressBar.AnimationDuration = (int)sliderAnimationDuration.Value;

    // Change the easing function based on a dropdown selection.
    switch (comboEasingFunction.SelectedItem.ToString())
    {
        case "Linear":
            progressBar.AnimationEasingFunc = SiticoneHBarsProgress.AnimationEasing.Linear;
            break;
        case "EaseInQuad":
            progressBar.AnimationEasingFunc = SiticoneHBarsProgress.AnimationEasing.EaseInQuad;
            break;
        case "EaseOutQuad":
            progressBar.AnimationEasingFunc = SiticoneHBarsProgress.AnimationEasing.EaseOutQuad;
            break;
        case "EaseInOutQuad":
            progressBar.AnimationEasingFunc = SiticoneHBarsProgress.AnimationEasing.EaseInOutQuad;
            break;
        case "EaseInCubic":
            progressBar.AnimationEasingFunc = SiticoneHBarsProgress.AnimationEasing.EaseInCubic;
            break;
        case "EaseOutCubic":
            progressBar.AnimationEasingFunc = SiticoneHBarsProgress.AnimationEasing.EaseOutCubic;
            break;
        case "EaseInOutCubic":
            progressBar.AnimationEasingFunc = SiticoneHBarsProgress.AnimationEasing.EaseInOutCubic;
            break;
    }

    // Apply a new progress value to see the updated animation behavior.
    progressBar.Value = 70;
}
```

***

### Key Points

| Aspect              | Details                                                                                                                                                               |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Customization       | Developers can fully customize animation duration and easing function to match UI design requirements.                                                                |
| State Notifications | The `IsAnimating` property and associated events (`AnimationCompleted`, `AnimationStateChanged`) enable developers to monitor and respond to animation state changes. |
| Smooth Transitions  | The use of easing functions ensures smooth, visually appealing transitions between progress values.                                                                   |
| Immediate Control   | The `StopAnimation()` method allows immediate halting of animations for cases requiring instant UI updates.                                                           |

***

### Best Practices

| Practice                         | Description                                                                                                                                                   |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Use Appropriate Durations        | Choose an animation duration that feels natural for your application; durations that are too short may not be noticeable, while too long may frustrate users. |
| Select the Right Easing Function | Match the easing function to the type of transition desired. For example, use `EaseInOutCubic` for smooth transitions that start and end gradually.           |
| Monitor Animation State          | Use the `IsAnimating` property and related events to synchronize other UI elements or logic with the animation progress.                                      |
| Test User Interactions           | When enabling user interactions, ensure that animations do not conflict with manual updates to the progress value.                                            |

***

### Common Pitfalls

| Pitfall                                    | Cause/Resolution                                                                                                                                                     |
| ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Animation Not Starting                     | Occurs if the target value is too close to the current value. Ensure that the new value differs significantly to trigger the animation.                              |
| Inconsistent Animation Duration            | Setting durations below the minimum (16 ms) may lead to unexpected behavior. Always verify that the duration meets the minimum requirement.                          |
| Ignoring Animation State Notifications     | Failing to handle the `AnimationStateChanged` event might result in misaligned UI logic. Always subscribe to state events when necessary for proper synchronization. |
| Conflicting User Interaction and Animation | When `UserInteractionEnabled` is active, ensure that user-initiated updates do not disrupt the animation logic unexpectedly.                                         |

***

### Usage Scenarios

| Scenario                      | Implementation Details                                                                                                                                           |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Progressive Loading Indicator | Use the animation to smoothly transition the progress indicator as content loads, providing visual feedback to users.                                            |
| Real-time Data Monitoring     | Animate the progress bar in response to real-time data updates (e.g., CPU usage, network activity) to create a dynamic monitoring dashboard.                     |
| Interactive User Input        | Allow users to change progress values interactively while still displaying smooth animated transitions to reflect those changes.                                 |
| Synchronized UI Updates       | Use the animation events to trigger other UI updates (e.g., updating status text) when an animation completes or starts, ensuring a coordinated user experience. |

***

### Review

| Category            | Review Comments                                                                                                                          |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| Flexibility         | The animation control offers extensive customization, making it adaptable to a variety of UI requirements.                               |
| Ease of Integration | Clear properties and events provide a straightforward integration path for developers familiar with .NET WinForms.                       |
| Visual Appeal       | Easing functions and smooth transitions enhance the overall user experience, making the progress indicator feel modern and responsive.   |
| Robustness          | Built-in safeguards, such as minimum duration and precision thresholds, ensure that animations behave reliably under various conditions. |

***

### Summary

The Animation Control feature of the `SiticoneHBarsProgress` component is designed to provide smooth, customizable animated transitions between progress values. By configuring properties such as `AnimationDuration` and `AnimationEasingFunc`, and by handling events like `AnimationCompleted` and `AnimationStateChanged`, developers can create visually engaging and responsive progress indicators. The feature is robust and flexible, allowing for both automatic and user-driven animations, with built-in mechanisms to handle edge cases gracefully.

***

### Additional Notes

| Note                              | Details                                                                                                                                                      |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Integration with User Interaction | When combining animation with user interaction, consider potential conflicts; use `StopAnimation()` to ensure the UI state remains consistent.               |
| Testing in Different Environments | Always test the animation on different machines and displays, as rendering performance might vary, affecting the smoothness of the animation.                |
| Combining with Other Features     | The animation control works seamlessly with other customization features (like color schemes and line configurations), allowing for a fully branded control. |

***

This comprehensive guide on Animation Control should provide all the necessary details and examples to help developers integrate and customize the animation behavior in their .NET WinForms applications using the `SiticoneHBarsProgress` component.
