> 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/chip-and-group-controls/siticone-groupbutton/selection-and-interactive-states.md).

# Selection and Interactive States

Selection and Interactive States enable the control to reflect user interactions—such as hovering, clicking, and selection—with dynamic visual feedback, making it intuitive and responsive.

## Overview

The Selection and Interactive States feature allows the control to transition between various visual states, such as normal, hovered, pressed, and selected. With properties like `IsSelected`, `SelectedColor`, `NormalColor`, `HoverColor`, `PressColor`, `TextColor`, and `SelectedTextColor`, developers can fine-tune the appearance of the control based on user interaction. In addition, built-in events such as `DoubleTapped` and `LongPressed` provide hooks for more advanced interactivity. The feature also manages state transitions and animations (e.g., selection and deselection animations) to ensure smooth visual feedback.

***

### Properties and Configuration

The table below summarizes the key properties related to Selection and Interactive States:

| Property Name     | Description                                                                                                             | Default Value / Range               | Sample Usage Example                                            |
| ----------------- | ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------- | --------------------------------------------------------------- |
| IsSelected        | Gets or sets whether the button is in a selected state; selecting one button in a group automatically deselects others. | Boolean (default is false)          | `myButton.IsSelected = true;`                                   |
| SelectedColor     | The background color when the button is selected.                                                                       | ColorTranslator.FromHtml("#298ff5") | `myButton.SelectedColor = ColorTranslator.FromHtml("#298ff5");` |
| NormalColor       | The default background color of the button in its normal (unselected) state.                                            | Color.FromArgb(100, 100, 100)       | `myButton.NormalColor = Color.FromArgb(100, 100, 100);`         |
| HoverColor        | The background color when the mouse hovers over the button.                                                             | Color.FromArgb(80, 80, 80)          | `myButton.HoverColor = Color.FromArgb(80, 80, 80);`             |
| PressColor        | The background color when the button is pressed.                                                                        | Color.FromArgb(50, 50, 50)          | `myButton.PressColor = Color.FromArgb(50, 50, 50);`             |
| TextColor         | The color of the button text in its normal state.                                                                       | Color.LightGray                     | `myButton.TextColor = Color.LightGray;`                         |
| SelectedTextColor | The color of the button text when the button is selected.                                                               | Color.White                         | `myButton.SelectedTextColor = Color.White;`                     |

***

### Key Points

<table><thead><tr><th width="288">Key Point</th><th>Details</th></tr></thead><tbody><tr><td>Dynamic State Transitions</td><td>The control visually transitions between states (normal, hover, press, and selected) based on user interaction.</td></tr><tr><td>Group Selection Management</td><td>When one control is selected, the implementation ensures other grouped buttons are automatically deselected, preserving a coherent state.</td></tr><tr><td>Animated Feedback</td><td>Built-in animations provide smooth transitions, such as fading between colors, to enhance user experience during selection or hover events.</td></tr><tr><td>Customizable Appearance</td><td>Developers have full control over the color properties for various interactive states, ensuring the control fits seamlessly into different UI themes.</td></tr></tbody></table>

***

### Best Practices

| Best Practice                        | Description                                                                                                                                                         | Example Code Snippet                                                                                                                                                        |
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Define Clear Visual States           | Use distinct colors for normal, hover, press, and selected states to provide clear visual feedback and prevent user confusion.                                      | `csharp<br>myButton.NormalColor = Color.Gray;<br>myButton.HoverColor = Color.DarkGray;<br>myButton.PressColor = Color.DimGray;<br>myButton.SelectedColor = Color.Blue;<br>` |
| Use Grouping for Exclusive Selection | When using multiple buttons in a group, leverage the automatic deselection feature by setting the `IsSelected` property; this ensures only one is active at a time. | `csharp<br>button1.IsSelected = true;<br>// button2 and button3 will automatically deselect if they were selected<br>`                                                      |
| Balance Animation Speed              | Adjust the animation speed to achieve a smooth but responsive transition; avoid too slow or too fast transitions that may hinder user experience.                   | `csharp<br>myButton.AnimationSpeed = 0.09f;<br>`                                                                                                                            |

***

### Common Pitfalls

| Pitfall                             | Description                                                                                             | How to Avoid                                                                                                    |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| Inconsistent State Feedback         | Inadequate differentiation between states (e.g., similar colors for hover and press) may confuse users. | Choose contrasting colors for each state and test the control in various interaction scenarios.                 |
| Overcomplicated Group Behavior      | Improper management of grouped buttons can lead to multiple buttons appearing selected simultaneously.  | Ensure that the selection logic properly deselects other buttons when one is activated.                         |
| Neglecting Animation Responsiveness | Extremely slow or fast animation speeds may reduce the perceived responsiveness of the control.         | Test and adjust the `AnimationSpeed` value for optimal visual feedback and performance on your target hardware. |

***

### Usage Scenarios

| Scenario                  | Description                                                                                                                                  | Sample Integration Code                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Form Submission Buttons   | Use selection states to indicate which action is currently active, such as highlighting the selected button when confirming a submission.    | `csharp<br>// Initialize a submission button with interactive states<br>SiticoneGroupButton submitButton = new SiticoneGroupButton();<br>submitButton.Text = "Submit";<br>submitButton.NormalColor = Color.Gray;<br>submitButton.HoverColor = Color.DarkGray;<br>submitButton.PressColor = Color.DimGray;<br>submitButton.SelectedColor = Color.Blue;<br>submitButton.TextColor = Color.LightGray;<br>submitButton.SelectedTextColor = Color.White;<br>this.Controls.Add(submitButton);<br>`                        |
| Toggle Buttons in a Group | In multi-option dialogs or toolbars, use the selection state to allow only one active button, providing clear feedback on the user's choice. | `csharp<br>// Grouping buttons to ensure only one is selected at a time<br>SiticoneGroupButton option1 = new SiticoneGroupButton();<br>SiticoneGroupButton option2 = new SiticoneGroupButton();<br>option1.Text = "Option 1";<br>option2.Text = "Option 2";<br>option1.SelectedColor = Color.Green;<br>option2.SelectedColor = Color.Green;<br>option1.IsSelected = true; // Selecting option 1 will automatically deselect option 2 if selected<br>this.Controls.Add(option1);<br>this.Controls.Add(option2);<br>` |

***

### Real Life Usage Scenarios

| Real Life Scenario              | Description                                                                                                                                 | Example Implementation                                                                                                              |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| Interactive Dashboard Controls  | In a dashboard, use selection states to allow users to switch between different views or metrics by highlighting the active selection.      | `csharp<br>dashboardButton1.IsSelected = true;<br>// Other dashboard buttons automatically update their states<br>`                 |
| Multimedia Application Controls | Use interactive state transitions to indicate which media control (play, pause, stop) is active, enhancing user feedback in a media player. | `csharp<br>playButton.SelectedColor = Color.Red;<br>pauseButton.SelectedColor = Color.Red;<br>// Clicking play deselects pause<br>` |

***

### Troubleshooting Tips

| Issue                                   | Potential Cause                                                                                      | Resolution                                                                                                       |
| --------------------------------------- | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| Button Remains Selected Unintentionally | A logic error in the button group may fail to deselect previously selected buttons.                  | Verify that the selection logic properly iterates through the group and sets `IsSelected` to false on others.    |
| Delayed State Transitions               | Overly slow animation speeds can make the control seem unresponsive during state transitions.        | Adjust the `AnimationSpeed` property to balance smooth transitions with responsiveness.                          |
| Inconsistent Color Transitions          | Incorrect property assignments may lead to abrupt or inconsistent color changes during interactions. | Ensure that each state property (NormalColor, HoverColor, etc.) is assigned proper values and tested thoroughly. |

***

### Integration Code Sample

The following example demonstrates how to integrate Selection and Interactive States into a simple WinForms application:

```csharp
using System;
using System.Drawing;
using System.Windows.Forms;
using SiticoneNetFrameworkUI; // Ensure the correct namespace is referenced

public class MainForm : Form
{
    public MainForm()
    {
        // Initialize and configure a SiticoneGroupButton with interactive states
        SiticoneGroupButton interactiveButton = new SiticoneGroupButton
        {
            Text = "Click Me",
            Size = new Size(220, 50),
            Location = new Point(20, 20),
            NormalColor = Color.Gray,
            HoverColor = Color.DarkGray,
            PressColor = Color.DimGray,
            SelectedColor = Color.Blue,
            TextColor = Color.LightGray,
            SelectedTextColor = Color.White,
            // Set the initial selected state if desired
            IsSelected = false,
            // Optionally adjust animation speed
            AnimationSpeed = 0.09f
        };

        // Subscribe to interactive events if needed
        interactiveButton.DoubleTapped += (sender, e) =>
        {
            MessageBox.Show("Button was double-tapped!");
        };

        interactiveButton.LongPressed += (sender, e) =>
        {
            MessageBox.Show("Button was long-pressed!");
        };

        // Set the button to selected when clicked
        interactiveButton.Click += (sender, e) =>
        {
            interactiveButton.IsSelected = true;
        };

        // Add the button to the form
        Controls.Add(interactiveButton);
    }

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

***

### Review

<table><thead><tr><th width="225">Review Aspect</th><th>Details</th></tr></thead><tbody><tr><td>Visual Feedback</td><td>The control provides clear and dynamic visual feedback for each interaction state, improving user intuitiveness and engagement.</td></tr><tr><td>Ease of Configuration</td><td>Simple property assignments allow for quick customization of colors and states without extensive code modifications.</td></tr><tr><td>Group Management</td><td>Automatic deselection within groups ensures that only one control is active, streamlining user interactions in multi-choice interfaces.</td></tr><tr><td>Responsiveness</td><td>Built-in animations offer a balance between smooth transitions and responsive user feedback when interacting with the control.</td></tr></tbody></table>

***

### Summary

<table><thead><tr><th width="263">Summary Point</th><th>Description</th></tr></thead><tbody><tr><td>Dynamic Interaction States</td><td>Selection and Interactive States provide a robust mechanism for managing user interactions and visual feedback through state transitions.</td></tr><tr><td>Customizable Appearance</td><td>With properties controlling various color states and animations, the control can be tailored to match any UI theme.</td></tr><tr><td>Integrated Group Behavior</td><td>Supports automatic management of grouped selections, ensuring only one button is active at a time for clear, intuitive navigation.</td></tr><tr><td>Enhanced Usability</td><td>The combination of visual state changes and interactive events such as double-tap and long-press improves overall user engagement and accessibility.</td></tr></tbody></table>

***

### Additional Useful Sections

#### Frequently Asked Questions (FAQ)

| Question                                   | Answer                                                                                                                                                 |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| How do I programmatically select a button? | Set the `IsSelected` property to true on the desired button; grouped buttons will automatically deselect each other.                                   |
| Can I change the state colors at runtime?  | Yes, update properties like `NormalColor`, `HoverColor`, `PressColor`, and `SelectedColor` dynamically as needed.                                      |
| What if multiple buttons remain selected?  | Ensure that the grouping logic is correctly implemented, so that selecting one button sets the `IsSelected` property to false for others in the group. |

#### Integration Checklist

<table><thead><tr><th width="281">Checklist Item</th><th>Status</th></tr></thead><tbody><tr><td>Configure State Colors</td><td>Verify that properties for normal, hover, press, and selected states are correctly set for each control.</td></tr><tr><td>Test Group Selection Behavior</td><td>Confirm that selecting one button in a group automatically deselects all other buttons.</td></tr><tr><td>Validate Animation Speeds</td><td>Adjust and test the <code>AnimationSpeed</code> property to ensure smooth yet responsive state transitions.</td></tr><tr><td>Check Event Handling</td><td>Ensure that interactive events (e.g., <code>DoubleTapped</code>, <code>LongPressed</code>) are wired correctly and perform as expected.</td></tr></tbody></table>

***

By following this comprehensive documentation for Selection and Interactive States, developers can effectively integrate dynamic state management and user interactivity into their .NET WinForms applications, resulting in a more responsive and intuitive user interface.
