# Behavior & Value Management

## Overview

The Behavior & Value Management feature governs how the slider’s values are set, validated, and updated. It exposes properties such as Minimum, Maximum, LowerValue, UpperValue, Step, SnapToTick, and the read-only ValuesDifference. Additionally, it raises events (LowerValueChanged and UpperValueChanged) to notify subscribers whenever the slider’s values change. This section is essential for ensuring that the slider always operates within a logical numeric range while providing smooth animations and precise value adjustments.

***

### Key Points

<table><thead><tr><th width="174">Element</th><th>Description</th><th width="134">Default Value</th><th>Notes</th></tr></thead><tbody><tr><td>Minimum</td><td>Defines the lower boundary of the slider’s range.</td><td>0</td><td>LowerValue and UpperValue will never fall below this value.</td></tr><tr><td>Maximum</td><td>Defines the upper boundary of the slider’s range.</td><td>100</td><td>Must be set higher than Minimum.</td></tr><tr><td>LowerValue</td><td>Represents the current value of the lower thumb.</td><td>25</td><td>Adjusting this value triggers LowerValueChanged; cannot exceed UpperValue.</td></tr><tr><td>UpperValue</td><td>Represents the current value of the upper thumb.</td><td>75</td><td>Adjusting this value triggers UpperValueChanged; cannot be less than LowerValue.</td></tr><tr><td>Step</td><td>Determines the incremental value by which the slider changes.</td><td>1</td><td>Used when adjusting values via keyboard or programmatically.</td></tr><tr><td>SnapToTick</td><td>Enables snapping the value to the nearest tick mark when moving the slider.</td><td>false</td><td>When true, values adjust to the nearest tick defined by tickFrequency.</td></tr><tr><td>ValuesDifference</td><td>Provides the computed difference between UpperValue and LowerValue.</td><td>50</td><td>Read-only; useful for understanding the current range width.</td></tr></tbody></table>

***

### Best Practices

| Practice Area                 | Recommendation                                                                                                  | Example                                                                                      |
| ----------------------------- | --------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| Validate Range Boundaries     | Always ensure that Maximum > Minimum and that both LowerValue and UpperValue are initialized within this range. | `slider.Minimum = 0; slider.Maximum = 200; slider.LowerValue = 50; slider.UpperValue = 150;` |
| Consistent Increment Settings | When using a Step value greater than 1, consider enabling SnapToTick to enforce discrete value adjustments.     | `slider.Step = 5; slider.SnapToTick = true;`                                                 |
| Subscribe to Value Events     | Attach event handlers to LowerValueChanged and UpperValueChanged to respond to user changes dynamically.        | See code example below.                                                                      |
| Programmatic Value Changes    | Always change LowerValue and UpperValue using their properties to trigger validations, animations, and events.  | `slider.LowerValue = 30; slider.UpperValue = 80;`                                            |

***

### Common Pitfalls

<table><thead><tr><th width="220">Pitfall</th><th>Explanation</th><th>Recommendation</th></tr></thead><tbody><tr><td>Inconsistent Range Settings</td><td>Setting LowerValue greater than UpperValue (or vice versa) may lead to unexpected behavior.</td><td>Always ensure that LowerValue ≤ UpperValue by validating or using the provided property setters.</td></tr><tr><td>Ignoring Snap Settings</td><td>Disabling SnapToTick when precise, discrete value changes are needed can result in unexpected values.</td><td>Enable SnapToTick when you require values to conform to defined tick intervals or Step increments.</td></tr><tr><td>Skipping Event Subscriptions</td><td>Failing to subscribe to value change events can cause the UI or related logic to not update as expected.</td><td>Attach appropriate event handlers to LowerValueChanged and UpperValueChanged for dynamic UI updates.</td></tr></tbody></table>

***

### Usage Scenarios

| Scenario                | Description                                                                                                  | Code Example Snippet                                         |
| ----------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------ |
| Dynamic Data Filtering  | Use the slider to select a numeric range for filtering data in real time (e.g., filtering search results).   | `slider.LowerValue = 20; slider.UpperValue = 80;`            |
| Parameter Configuration | Allow users to set parameters (such as volume or brightness) by selecting a sub-range within the full range. | `slider.Minimum = 0; slider.Maximum = 100; slider.Step = 5;` |
| Form Input Validation   | Integrate the slider into forms where users must choose a value range (e.g., age range, score range).        | `if(slider.ValuesDifference < 10) { /* warn user */ }`       |

***

### Real Life Usage Scenarios

<table><thead><tr><th width="213">Scenario</th><th>Description</th><th>Implementation Example</th></tr></thead><tbody><tr><td>Price Range Selector</td><td>Users select a price range for products on an e-commerce platform.</td><td><code>slider.Minimum = 0; slider.Maximum = 1000; slider.Step = 50; slider.LowerValue = 200; slider.UpperValue = 800;</code></td></tr><tr><td>Time Interval Picker</td><td>Selecting a start and end time for scheduling or analytics.</td><td><code>slider.Minimum = 0; slider.Maximum = 24; slider.Step = 1; slider.LowerValue = 8; slider.UpperValue = 17;</code></td></tr><tr><td>Data Analysis Interval</td><td>Defining a sub-range for data visualization or statistical analysis within a larger dataset.</td><td><code>slider.Minimum = 0; slider.Maximum = 100; slider.Step = 2; slider.LowerValue = 10; slider.UpperValue = 60;</code></td></tr></tbody></table>

***

### Troubleshooting Tips

| Issue                      | Possible Cause                                                                          | Resolution                                                                                                             |
| -------------------------- | --------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| Events Not Firing          | Event handlers may not be attached properly.                                            | Verify that you have subscribed to LowerValueChanged and UpperValueChanged events correctly.                           |
| Out-of-Range Values        | Programmatic changes might set values outside the defined Minimum and Maximum.          | Ensure that values assigned to LowerValue and UpperValue remain within the valid range defined by Minimum and Maximum. |
| Improper Snapping Behavior | SnapToTick may be disabled or not configured correctly in conjunction with Step values. | Enable SnapToTick and adjust tickFrequency or Step to match your intended value increments.                            |

***

### Code Examples

Below is an extensive demo illustrating how to integrate the Behavior & Value Management feature into a .NET WinForms application.

```csharp
using System;
using System.Windows.Forms;
using SiticoneNetFrameworkUI;

public class SliderDemoForm : Form
{
    private SiticoneHRangeSlider slider;

    public SliderDemoForm()
    {
        // Initialize the slider with value boundaries and appearance settings
        slider = new SiticoneHRangeSlider
        {
            Minimum = 0,
            Maximum = 100,
            LowerValue = 20,
            UpperValue = 80,
            Step = 5,
            SnapToTick = true,
            Location = new System.Drawing.Point(20, 20),
            Size = new System.Drawing.Size(400, 100)
        };

        // Subscribe to value change events
        slider.LowerValueChanged += Slider_LowerValueChanged;
        slider.UpperValueChanged += Slider_UpperValueChanged;

        // Add the slider to the form controls
        Controls.Add(slider);
    }

    // Event handler for changes in the lower value
    private void Slider_LowerValueChanged(object sender, SiticoneHRangeSlider.OnLowerValueChangedEventArgs e)
    {
        Console.WriteLine("Lower value changed to " + e.Value + " with range difference: " + e.ValuesDifference);
        // Additional logic can be implemented here to update other UI elements or data
    }

    // Event handler for changes in the upper value
    private void Slider_UpperValueChanged(object sender, SiticoneHRangeSlider.OnUpperValueChangedEventArgs e)
    {
        Console.WriteLine("Upper value changed to " + e.Value + " with range difference: " + e.ValuesDifference);
        // Additional logic can be implemented here to update other UI elements or data
    }

    [STAThread]
    public static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new SliderDemoForm());
    }
}
```

This example demonstrates how to set up the slider, configure its boundaries and stepping behavior, and subscribe to its events to handle dynamic value changes.

***

### Review

<table><thead><tr><th width="182">Aspect</th><th>Evaluation</th></tr></thead><tbody><tr><td>Flexibility</td><td>The feature supports comprehensive value management, allowing both user-driven and programmatic adjustments.</td></tr><tr><td>Robustness</td><td>Built-in validations and event triggers ensure that value changes are logical and remain within defined limits.</td></tr><tr><td>Integration Ease</td><td>Simple property assignments and event subscriptions facilitate smooth integration into existing WinForms projects.</td></tr></tbody></table>

***

### Summary

The Behavior & Value Management feature of the SiticoneHRangeSlider control provides robust handling of value ranges, discrete increments, and event notifications. By leveraging properties such as Minimum, Maximum, LowerValue, UpperValue, and Step along with SnapToTick, developers can ensure precise control over slider behavior. Adhering to the best practices and recommendations outlined in this documentation will help maintain consistency, enhance user experience, and prevent common integration pitfalls.

***

### Additional Considerations

* Ensure that the slider’s range values are updated dynamically if your application’s context changes (e.g., when the available data range updates).
* Use the provided events to trigger additional UI updates or calculations elsewhere in your application.
* Combine Behavior & Value Management with appearance and interaction customization features for a fully integrated, responsive control.

This comprehensive documentation should enable developers to integrate and utilize the Behavior & Value Management feature efficiently and effectively in their .NET WinForms applications.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-siticoneframework.gitbook.io/home/net-framework-or-net-core-ui/sliders-and-range/siticone-hrangeslider/behavior-and-value-management.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
