dotnet/winforms
Vedi su GitHubProposal: add SelectionStart and SelectionEnd to TrackBar
Open
#2642 aperta il 6 gen 2020
api-approveddesign-discussionhelp wantedtenet-compatibility-OS
Metriche repository
- Star
- (4100 star)
- Metriche merge PR
- (Merge medio 14g 22h) (56 PR mergiate in 30 g)
Descrizione
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:

We could add the following APIs to TrackBar:
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
SelectionStartandSelectionEndbe if we haven't enabled selections? In my experiments I set them to0which worked nicely. - In my prototype implementation, I set
ShowSelectionRangetotrueif the user setsSelectionStart/SelectionEnd. One option could be to removeShowSelectionRangeand setSelectionStart/SelectionEndto minus one or have some logic that sets theTrackBarstyle toTBS_ENABLESELRANGEif 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
SelectionStartandSelectionEndorSelectionStartandSelectionLengthor some sort ofSelectionRangestruct that encapsulates this? (e.gMonthCalendar.SelectionRange)