Progress Indicator

A simple, circular progress display around the button that indicates playback or loading progress.

Overview

The Progress Indicator feature in the SiticonePlayPauseButton control provides visual feedback by drawing a circular arc around the button to represent the current progress (ranging from 0.0 to 1.0). It is particularly useful for scenarios such as audio or video playback, file loading, or any process where a continuous progress update is beneficial. This feature is fully customizable, allowing developers to modify its visibility, progress value, and color to suit their application's design and requirements.


Feature Details

The following table summarizes the key properties associated with the Progress Indicator feature:

Property
Type
Default Value
Description

PlayProgress

float

0.0

Represents the current progress (0.0 to 1.0).

ShowProgress

bool

false

Determines whether the circular progress indicator is visible.

ProgressColor

Color

Color.FromArgb(128, 0, 255, 0)

Specifies the color of the progress arc, allowing for semi-transparent effects.


Code Examples

Basic Integration

Below is an example of how to integrate the Progress Indicator feature into your WinForms application:

using System;
using System.Drawing;
using System.Windows.Forms;
using SiticoneNetFrameworkUI;

namespace ProgressIndicatorDemo
{
    public partial class MainForm : Form
    {
        private SiticonePlayPauseButton playPauseButton;

        public MainForm()
        {
            InitializeComponent();
            InitializeCustomComponents();
        }

        private void InitializeCustomComponents()
        {
            playPauseButton = new SiticonePlayPauseButton
            {
                Location = new Point(50, 50),
                Size = new Size(80, 80),
                // Enable the progress indicator
                ShowProgress = true,
                // Set initial progress to 0%
                PlayProgress = 0.0f,
                // Customize the progress color (semi-transparent green)
                ProgressColor = Color.FromArgb(128, 0, 255, 0)
            };

            // Optionally, subscribe to state change events
            playPauseButton.StateChanged += PlayPauseButton_StateChanged;

            // Add the control to the form
            this.Controls.Add(playPauseButton);

            // Simulate progress update
            Timer progressTimer = new Timer
            {
                Interval = 100
            };
            progressTimer.Tick += ProgressTimer_Tick;
            progressTimer.Start();
        }

        private void ProgressTimer_Tick(object sender, EventArgs e)
        {
            // Update progress value gradually from 0.0 to 1.0
            if (playPauseButton.PlayProgress < 1.0f)
            {
                playPauseButton.PlayProgress += 0.01f;
            }
            else
            {
                // Reset progress to simulate continuous loading
                playPauseButton.PlayProgress = 0.0f;
            }
        }

        private void PlayPauseButton_StateChanged(object sender, EventArgs e)
        {
            // Handle state changes if needed
            Console.WriteLine("Play/Pause state changed.");
        }
    }
}

Advanced Customization

The following example demonstrates how to adjust the progress indicator dynamically based on an external event (e.g., a file download progress):

using System;
using System.Drawing;
using System.Windows.Forms;
using SiticoneNetFrameworkUI;

namespace AdvancedProgressDemo
{
    public partial class DownloadForm : Form
    {
        private SiticonePlayPauseButton playPauseButton;
        private Random random;

        public DownloadForm()
        {
            InitializeComponent();
            random = new Random();
            InitializeCustomComponents();
        }

        private void InitializeCustomComponents()
        {
            playPauseButton = new SiticonePlayPauseButton
            {
                Location = new Point(100, 100),
                Size = new Size(100, 100),
                ShowProgress = true,
                PlayProgress = 0.0f,
                ProgressColor = Color.FromArgb(150, 255, 0, 0) // semi-transparent red
            };

            // Add control to form
            this.Controls.Add(playPauseButton);

            // Simulate download progress update
            Timer downloadTimer = new Timer
            {
                Interval = 150
            };
            downloadTimer.Tick += DownloadTimer_Tick;
            downloadTimer.Start();
        }

        private void DownloadTimer_Tick(object sender, EventArgs e)
        {
            // Simulate progress update with random increments
            if (playPauseButton.PlayProgress < 1.0f)
            {
                playPauseButton.PlayProgress += (float)(random.NextDouble() * 0.05);
            }
            else
            {
                // Download complete, reset indicator
                playPauseButton.PlayProgress = 0.0f;
            }
        }
    }
}

Key Points

The table below highlights the important aspects of the Progress Indicator feature:

Aspect
Details

Range

Accepts progress values between 0.0 and 1.0.

Visibility

Controlled by the ShowProgress property; must be set to true to display the progress arc.

Customization

ProgressColor allows you to define both solid and semi-transparent colors for the progress indicator.

Refresh Behavior

Changing the progress value calls Invalidate(), triggering a repaint of the control for smooth updates.


Best Practices

Use the following guidelines to ensure optimal usage of the Progress Indicator feature:

Recommendation
Rationale

Set ShowProgress to true only when needed

Avoid unnecessary UI clutter when progress information is not required.

Use incremental updates for PlayProgress

Ensure smooth visual updates by making gradual changes to the progress value.

Choose appropriate ProgressColor values

Use semi-transparent colors to avoid a harsh UI look while still being noticeable.


Common Pitfalls

Avoid these issues when implementing the Progress Indicator:

Issue
Explanation
Prevention

Setting PlayProgress outside the [0.0,1.0] range

The property clamps values, which might not reflect intended progress.

Validate progress values before assigning them.

Not calling Invalidate after progress changes

Without refreshing, updates to progress might not be visible.

Rely on the property setter, which already calls Invalidate().

Overusing the progress indicator

Displaying the progress indicator when unnecessary may confuse users.

Only enable progress visualization when required by the application.


Usage Scenarios

The following scenarios illustrate when and how to use the Progress Indicator:

Scenario
Description
Sample Code Reference

Media Playback Applications

Indicate the progress of audio/video playback with a circular arc.

See Basic Integration sample above.

File Loading or Downloading

Visualize the progress of file transfers or downloads, giving users real-time feedback.

See Advanced Customization sample above.

Background Task Monitoring

Display progress for background processes like data processing or long-running computations.

Integrate with a timer-based update mechanism as demonstrated.


Review

When reviewing the implementation of the Progress Indicator feature, consider the following checklist:

Checklist Item
Status/Recommendation

Proper Initialization

Ensure ShowProgress is enabled and PlayProgress is set within the valid range.

Smooth Animation

Verify that changes in progress are rendered without flickering or delays.

Consistent Styling

Confirm that ProgressColor matches the overall UI design and provides clear visual feedback.

Event Handling

Ensure any associated events (such as state changes) do not interfere with the progress updates.


Summary

The Progress Indicator feature enhances the SiticonePlayPauseButton control by providing a visual representation of progress through a customizable circular arc. With properties to control the progress value, visibility, and color, developers can easily integrate and tailor this feature for various scenarios such as media playback, file downloads, or background task monitoring. Proper integration with timers and adherence to best practices ensures a smooth and effective user experience.


Additional Sections

Integration Tips

Tip
Explanation

Synchronize with external events

Use timers or background workers to update PlayProgress reliably.

Consider accessibility

Ensure that visual progress indicators are supplemented with alternative feedback for accessible applications.

Test under different UI scales

Verify that the progress arc renders correctly at various control sizes.

Demo Projects

For a full demo of the Progress Indicator feature, consider building a sample application that:

Demo Feature
Description

Media Player Simulation

Simulates a media player where the button's progress arc reflects the playback progress.

Download Manager

Mimics a file download manager where progress updates occur in real time.

By following this comprehensive documentation, developers can effectively integrate, customize, and troubleshoot the Progress Indicator feature within their applications, ensuring a polished and user-friendly experience.

Last updated