Display and Interaction

Display and Interaction governs how the progress bar communicates information visually and how users can directly interact with it, offering customization for text display and user input.

Overview

The Display and Interaction feature in the SiticoneHBarsProgress component provides options for rendering progress information—such as percentage text—and handling direct user input. Developers can configure text format and alignment, enable percentage display, and allow users to interact with the control (for example, clicking or dragging to update the progress value). This section covers the API elements, offers extensive code examples, and highlights key points, best practices, common pitfalls, usage scenarios, review, and summary for effective integration into .NET WinForms applications.


API Reference

Feature Element
Type
Default Value
Description

ShowPercentage

Property (bool)

false

Specifies whether the progress percentage text is displayed on the progress bar.

FormatString

Property (string)

"0"

Defines the format string used to display the progress percentage, allowing developers to control the number formatting or presentation style.

TextAlignment

Property (ContentAlignment)

MiddleCenter

Sets the alignment of the displayed percentage text within the control (e.g., TopLeft, MiddleCenter, BottomRight).

UserInteractionEnabled

Property (bool)

false

Enables or disables user interaction with the control; when enabled, users can click or drag on the progress bar to update its value.

GetValueAtPosition()

Method (Point)

N/A

Calculates and returns the progress value corresponding to a specific point (typically the mouse location) on the control, accounting for control padding and dimensions.

GetPositionFromValue()

Method (double)

N/A

Determines the graphical position on the control that corresponds to a specified progress value, useful for aligning other UI elements with the progress indicator.


Code Examples

Example 1: Enabling Percentage Display

This example demonstrates how to enable and customize the percentage display on the progress bar.

// Instantiate the progress bar control.
var progressBar = new SiticoneHBarsProgress();

// Enable percentage display.
progressBar.ShowPercentage = true;

// Set a custom format string for the percentage (e.g., include a "%" symbol explicitly).
progressBar.FormatString = "0";

// Change text alignment to top center.
progressBar.TextAlignment = ContentAlignment.TopCenter;

// Update progress value to see the percentage rendered.
progressBar.Value = 75;

Example 2: Configuring User Interaction

In this sample, user interaction is enabled to allow users to update the progress value by clicking or dragging on the control.

// Enable user interaction.
progressBar.UserInteractionEnabled = true;

// Handle an optional event for additional user feedback (for example, log the new value when the progress changes).
progressBar.ProgressChanged += (sender, e) =>
{
    Console.WriteLine($"Progress updated from {e.OldValue} to {e.NewValue}");
};

// Users can now click or drag on the progress bar to adjust the progress.
// The control uses GetValueAtPosition internally during mouse events to determine the new value.

Example 3: Synchronizing Display and Interaction

This comprehensive example demonstrates how to combine percentage display and user interaction, including custom text formatting and alignment.

// Create the progress bar control.
var progressBar = new SiticoneHBarsProgress();

// Enable percentage display with a custom format and alignment.
progressBar.ShowPercentage = true;
progressBar.FormatString = "#0"; // Forces integer display without decimals.
progressBar.TextAlignment = ContentAlignment.BottomRight;

// Enable user interaction so that users can adjust the progress by clicking/dragging.
progressBar.UserInteractionEnabled = true;

// Set an initial value.
progressBar.Value = 40;

// Optionally, subscribe to progress change events to update other UI components.
progressBar.ProgressChanged += (sender, e) =>
{
    // For example, update a label control.
    myStatusLabel.Text = $"Current Progress: {progressBar.Percentage}%";
};

Key Points

Aspect
Details

Customizable Text Display

Use ShowPercentage, FormatString, and TextAlignment to control how progress information is rendered on the control.

User Input Handling

Enabling UserInteractionEnabled allows users to interact with the progress bar directly, updating the value based on mouse location, which is internally calculated with GetValueAtPosition.

Flexibility

The separation of display and interaction features means that developers can choose to use either one or both, depending on the application’s requirements.

Utility Methods

Methods like GetValueAtPosition and GetPositionFromValue simplify the mapping between UI coordinates and progress values, making it easier to synchronize visual elements with the control.


Best Practices

Practice
Description

Consistent Formatting

Choose a FormatString that matches the overall UI style and ensures that percentage numbers are easily readable.

Appropriate Text Alignment

Set TextAlignment based on the control's layout and available space to ensure the percentage text does not obstruct other visual elements.

Enable Interaction When Appropriate

Only enable UserInteractionEnabled if the progress bar is intended to be interactive; otherwise, leave it disabled to prevent accidental changes.

Synchronize UI Elements

Use the ProgressChanged event to update other parts of the interface (e.g., labels, status indicators) when the progress value changes.


Common Pitfalls

Pitfall
Cause/Resolution

Unreadable Percentage Text

Using an improper FormatString or TextAlignment may result in text that is difficult to read; test different configurations to ensure clarity in all scenarios.

Accidental Progress Changes

Enabling user interaction on a read-only display may lead to unintended updates; only enable UserInteractionEnabled if direct manipulation is intended.

Misalignment with Other UI Components

Failure to use GetPositionFromValue for synchronizing other UI elements can cause inconsistencies; consider leveraging this method to position related indicators accurately.

Inconsistent Event Handling

Not subscribing to or handling the ProgressChanged event may result in missed updates elsewhere in the application; ensure that all UI components depending on progress updates are synchronized.


Usage Scenarios

Scenario
Implementation Details

Interactive Status Indicators

Enable UserInteractionEnabled to allow users to adjust progress values directly, and use the percentage display to provide immediate feedback on changes.

Dashboard Data Visualization

Display the progress percentage prominently by enabling ShowPercentage and adjusting the FormatString and TextAlignment; update adjacent UI elements using the ProgressChanged event.

Form-based Input Controls

Combine user interaction with clear text formatting to allow precise manual adjustments to progress values, which can be used in settings, configuration screens, or interactive wizards.

Synchronized UI Updates

Utilize the utility methods GetValueAtPosition and GetPositionFromValue to align progress indicators with other dynamic UI elements, ensuring consistency across the interface.


Review

Category
Review Comments

Flexibility

The separation of display and interaction features allows developers to opt-in to only those functionalities required for the specific application, making the control versatile.

Ease of Integration

Simple properties and clearly defined methods for text formatting and user input facilitate rapid integration and customization within .NET WinForms applications.

Visual Clarity

Customizable text display properties ensure that progress information is clear and well-aligned, supporting both aesthetic and functional requirements.

User Experience

Enabling direct user interaction provides a more engaging experience; however, careful testing is required to ensure that user input does not conflict with automated progress updates.


Summary

The Display and Interaction feature of the SiticoneHBarsProgress component allows developers to tailor how progress information is visually presented and how users can interact with the control. By configuring properties such as ShowPercentage, FormatString, and TextAlignment, developers can control the display of progress data. Additionally, enabling UserInteractionEnabled and utilizing utility methods like GetValueAtPosition and GetPositionFromValue facilitates a responsive, interactive experience. Following the provided best practices and avoiding common pitfalls will help ensure that the progress bar functions as a clear and engaging element in your application's UI.


Additional Notes

Note
Details

Integration with Other Features

The Display and Interaction settings work harmoniously with Animation Control and Appearance and Styling, allowing for a unified and cohesive progress indicator.

Testing Across Different Resolutions

Verify that text display and interaction features perform consistently across various screen resolutions and DPI settings, ensuring a robust user experience on all devices.

Accessibility Considerations

When enabling percentage display, choose high-contrast colors and clear formatting to enhance accessibility for users with visual impairments.

Custom Event Handling

Consider adding custom event handling for user interactions to further integrate the progress bar with other application features, such as real-time updates or dynamic content loading.


This extensive documentation on Display and Interaction provides the essential details and examples needed to integrate and customize the interactive and display aspects of the SiticoneHBarsProgress component within your .NET WinForms applications.

Last updated