Sometimes it is useful to have the capability to edit multiple ranges using a single control. This can be introduced with a custom control – MultipleRangeTrackBar.
In this example we have implemented the following features and functionality:
1) The capability to have multiple tick marks within this control.
2) The EditValue property of this control is a special RangeListclass which contains a list of TrackBarRange instances.
3) A couple of methods are intended for adding, changing and removing ticks:
- AddNewRange(int minimum, int maximum) – add a new range at a specific position. If it intersects with one of the existing ranges it will not be created.
- AddNewRange() – add a new range at the (0, 0) position. It has the same behavior as the previous method.
- ChangeValue(int minimum, int maximum, int index) – changes the value of the thumb by a particular index in the EditValue’s list. The new value will be set to a new TracKBarRange object with a special minimum and maximum. If it intersects with one of the existing ranges it will not be changed.
- ChangeValue(TrackBarRange range, int index) – The new value will be set to the range parameter. It has the same behavior as the previous method.
- RemoveRange(int index) – removes the thumb, by a particular index in the EditValue’s list. The first range cannot be deleted. Calling this method with the 0 parameter will do nothing.
4) The new EditValueChanged and the EditValueChanging events fire after successful completion of any of the above methods. They also fire after changing the EditValue with a new RangeList instance.
5) The Intersect event with the IntersectEventArgs argument. Thumbs cannot be intersected in this control. When an end-user tries to intersect thumbs, this event is raised. This event allows you to specify whether or not a dragged thumb is about to be intersected. The event handler receives an argument of type IntersectEventArgs containing data related to this event:
- DraggedThumb – gets the index of the pair of ticks.
- ThumbType – gets the value of the ThubmType type that specifies the type of the dragged thumb (ThumbType .Maximum or ThumbType .Minimum).
- Value – gets the value where this intersection occurs.
6) The ThumbsCount property returns the number of thumbs.
7) A new method also was added:
GetValue(int index) – returns a TrackBarRange instance, which has a particular index in the EditValue list.
The current example shows how we implemented MultipleRangeTrackBar and how to use it.
Question Comments
Added By: Lorenzo Viola at: 5/20/2014 9:54:36 AM
Hello, very nice example !
I'm trying to draw on the background of the highlighted range a filled rectangle. So I'm trying to make this change on the "DrawRangeHighlight" method of your sample.
Could you please provide a working example so that the track bar will draw different filled coloured rectangles (color is being set on the rangelist) under every range ?
Thank you !
Best Regards
I've separated your question into another ticket - MultipleRangeTrackBar (E4443) - How to draw a colored rectangle between thumbs. Let's continue our discussion there.