dotnet/winforms
GitHub で見るProposal: add SelectionStart and SelectionEnd to TrackBar
Open
#2,642 opened on 2020年1月6日
api-approveddesign-discussionhelp wantedtenet-compatibility-OS
Repository metrics
- Stars
- (4,100 stars)
- PR merge metrics
- (平均マージ 14d 22h) (30d で 56 merged PRs)
説明
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)