> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/gum/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/gum/code/controls/slider.md).

# Slider

## Introduction

The Slider control provides a way for the user to change a value by dragging the slider *thumb*.

## Code Example: Creating a Slider

The following code creates a Slider which allows the user to select a value between 0 and 30, inclusive. The `IsSnapToTickEnabled` property results in the value being snapped to the `TickFrequency` value. In this case, the value is used to force whole numbers.

```csharp
// Initialize
var label = new Label();
label.AddToRoot();
label.X = 50;
label.Y = 24;

var slider = new Slider();
slider.AddToRoot();
slider.X = 50;
slider.Y = 50;
slider.Minimum = 0;
slider.Maximum = 30;
slider.TicksFrequency = 1;
slider.IsSnapToTickEnabled = true;
slider.Width = 250;
slider.ValueChanged += (_, _) => 
    label.Text = $"Value: {slider.Value}";
slider.ValueChangeCompleted += (_, _) => 
    label.Text = $"Finished setting Value: {slider.Value}";
```

[Try on XnaFiddle.NET](https://xnafiddle.net/#snippet=H4sIAAAAAAAAA5WQUWvCMBSF_0oIe1CQ0dXtpaMPm6gI7mWWbYIg0VxsME20STY38b_vJnYaZAz21vPdc85N756OzNBVNLO1gw4VSljBpPgCmtF3VhPJFiBJThR8kLH_brXvZyrQ6wfOC_2stY3YG3rvkpOcokxvUfouIwWHuimbBBGSR35R18BTX6OnF_oJX1y5CmkM2a6B3YgWYrk2gxq2DtTyE4c359nITBTbFNp7-ootJHA0-JucPa-C29L_T7z_hUkHvZKpFSZmLknSx5y05h0yb5Pc627_5xYF7CzGr4IrDcGM7OOew3H0a3tPVxsJ9p9bBngeU2LIgLVCrchfa-nhGwhOLWwOAgAA)

<figure><img src="https://2695663588-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fzQmxQ1VeUFHcoo2c%2Fuploads%2FOEQYTnqBh6WVDOl8Pblk%2F13_22%2030%2010.gif?alt=media&amp;token=07b42855-eb05-498e-b30c-1cbc50d466c9" alt=""><figcaption><p>Slider reporting its value whenever the value changes or when the change completes</p></figcaption></figure>

## Value

Value is a `double` which represents the number displayed by the Slider. This value can change in response to UI events, binding, or explicit setting in code. Value is always between Minimum and Maximum, inclusive.

The following code directly sets Value:

```csharp
// Initialize
slider.Value = 25;
```

Setting a value outside of its bounds forces the value to the bounds. For example, the following code results in a value of 50:

```csharp
// Initialize
slider.Minimum = 0;
slider.Maximum = 50;
slider.Value = 100; // value is set to 50
```

Value can also be changed by changing either Minimum or Maximum:

```csharp
// Initialize
slider.Minimum = 0;
slider.Maximum = 100;

slider.Value = 80;
slider.Maximum = 75; // this sets Value to 75

slider.Value = 20;
slider.Minimum = 25; // this sets Value to 25
```

## Clicking the Track

`IsMoveToPointEnabled` controls what happens when the user clicks the track. It defaults to `false`.

### Stepping with LargeChange

When `IsMoveToPointEnabled` is `false`, each click on the track changes `Value` by `LargeChange` toward the cursor. Holding the button repeats the step until the thumb reaches the cursor.

```csharp
// Initialize
var label = new Label();
label.AddToRoot();
label.X = 50;
label.Y = 24;

var slider = new Slider();
slider.AddToRoot();
slider.X = 50;
slider.Y = 50;
slider.Width = 250;
slider.Minimum = 0;
slider.Maximum = 100;
slider.LargeChange = 10;
slider.ValueChanged += (_, _) =>
    label.Text = $"Value: {slider.Value}";
```

[Try on XnaFiddle.NET](https://xnafiddle.net/#snippet=H4sIAAAAAAAAA12P0QqCMBSGX-UwuiiQMKsbxYuKiMBuSipBiMVGDeYE3SoK3705h412te_7z_5xPmhbb1SBQlkp6iEmmGSYszdFIXrgCji-Ug4xCPqEpL0PR1EujB0vCEnLfVlKx5317NzvMdMYzDTmom2rOSO0snUHA-Zt5_8KrewbLWd_fGJE3ttvXLnTixSq0NqV-GXlxHd0gqsbXd2xuFET_ZIj5somBHLl-8EyhuHFg8sI4pan61yAPt2yKX1J3TAwk4F5HMLH7Wq6KELNF2tmwsF4AQAA)

`LargeChange` defaults to 25 regardless of `Minimum` and `Maximum`. On a slider from 0 to 1, one click jumps the whole range. On a slider from 0 to 1000, one click barely moves the thumb. Set `LargeChange` to fit your range, or set `IsMoveToPointEnabled` to `true`.

### Moving to the Cursor

When `IsMoveToPointEnabled` is `true`, clicking the track moves the thumb to the cursor. The thumb follows the cursor while the button is held. `LargeChange` is not used.

```csharp
// Initialize
var label = new Label();
label.AddToRoot();
label.X = 50;
label.Y = 24;

var slider = new Slider();
slider.AddToRoot();
slider.X = 50;
slider.Y = 50;
slider.Width = 250;
slider.Minimum = 0;
slider.Maximum = 100;
slider.IsMoveToPointEnabled = true;
slider.ValueChanged += (_, _) =>
    label.Text = $"Value: {slider.Value}";
```

[Try on XnaFiddle.NET](https://xnafiddle.net/#snippet=H4sIAAAAAAAAA12QUWvCMBDHv8oR9qAgo1b3UunDJiKCgmxFJxQkkkMDaQJtoqL43XdJiwvmKb_f3f3D5c4WzdxVLLO1wwGTWlrJlbwhy9iZ16D4ARXkoPECS3_v9SelDvb9U4jCfBtjI_dLvR_JE3eE6Ziw1D6tUVJg3cX9BAizrX8J7OQzsePdC2-lsCf_TCxXtEjlKtKx5NdODpNIL5qVOWNh1kZqO9P8oFBQj_-Q_6YNVw6nJ66PVCxdkqRfOfT2A9j3Ifc8mpUa6LR7F3i1lPEWOtMwnME9znq0pQl7_AHKGcQUgwEAAA)

`ValueChanged` is raised as the thumb moves. `ValueChangeCompleted` is raised once when the button is released, so use it for work that should not run every frame, such as saving a setting. `IsSnapToTickEnabled` applies in both modes.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/gum/code/controls/slider.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
