dotnet / dotnet/winforms

Proposal: add SelectionStart and SelectionEnd to TrackBar

Open
#2,642 10 comments 2 reactions 2 assignees Claimed by @lonitra View on GitHub
api-approved design-discussion help wanted tenet-compatibility-OS
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

You can set the `TBS_ENABLESELRANGE` on `TrackBar` and send the `TBM_SETSELSTART` and `TBM_SETSELSTART` to set the selection range
See docs
- https://docs.microsoft.com/en-us/windows/win32/controls/tbm-setselstart
- https://docs.microsoft.com/en-us/windows/win32/controls/tbm-setselend

Example:
![Screenshot 2020-01-06 at 16 31 38](https://user-images.githubusercontent.com/1275900/71832306-958b7000-30a2-11ea-93df-019c0e929f3c.png)
![Screen Recording 2020-01-06 at 04 32 pm](https://user-images.githubusercontent.com/1275900/71832296-915f5280-30a2-11ea-9ca2-24b47d3d35b8.gif)

We could add the following APIs to `TrackBar`:
```cs
public class TrackBar
{
...
public bool ShowSelectionRange { get; set; }
public int SelectionStart { get; set; }
public int SelectionEnd { get; set; }
...
}
```

## Discussion
- What should the default values of `SelectionStart` and `SelectionEnd` be if we haven't enabled selections? In my experiments I set them to `0` which worked nicely.
- In my prototype implementation, I set `ShowSelectionRange` to `true` if the user sets `SelectionStart`/`SelectionEnd`. One option could be to remove `ShowSelectionRange` and set `SelectionStart`/`SelectionEnd` to minus one or have some logic that sets the `TrackBar` style to `TBS_ENABLESELRANGE` if it is set to a custom value. However, this is negative as it leaves us with no way of removing the selection indicators once they've been created.
- Do we want `SelectionStart` and `SelectionEnd` or `SelectionStart` and `SelectionLength` or some sort of `SelectionRange` struct that encapsulates this? (e.g `MonthCalendar.SelectionRange`)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.