RadTrackBar with threshold

2 posts, 0 answers
  1. Matthew
    Matthew avatar
    3 posts
    Member since:
    Jul 2011

    Posted 31 May 2012 Link to this post

    I'm trying to configure the track bar with a threshold value that is greater than the min and less than the max, the user can only go past the threshold value by holding the Control key will dragging the slider. I have tried resetting the value in the Scroll event, that didn’t prevent the slider from continuing or change the value; I reset the value in the ValueChanged event, this did not prevent the slider from continuing but it did reset the value back to the threshold once the mouse was lifted.

    I was hoping to have a hard stop at the threshold, is this something that is possible?


  2. Ivan Todorov
    Ivan Todorov avatar
    688 posts

    Posted 05 Jun 2012 Link to this post

    Hi Matthew,

    Thank you for contacting us.

    Yes, it is possible to achieve such behavior. To do so, you need to listen for changes to the RadTrackBarElement.ValueProperty and apply the threshold if this is needed. The following code snippet demonstrates this:
    public Form1()
        this.radTrackBar1.TrackBarElement.RadPropertyChanged += new Telerik.WinControls.RadPropertyChangedEventHandler(TrackBarElement_RadPropertyChanged);
    int threshold = 50;
    void TrackBarElement_RadPropertyChanged(object sender, Telerik.WinControls.RadPropertyChangedEventArgs e)
        if (e.Property == RadTrackBarElement.ValueProperty)
            if (Control.ModifierKeys != Keys.Control)
                if (this.radTrackBar1.Value > threshold)
                    this.radTrackBar1.Value = Math.Min(this.radTrackBar1.Value, threshold);
                    this.radTrackBar1.TrackBarElement.RangeValue = Math.Min(this.radTrackBar1.Value, threshold) - this.radTrackBar1.Minimum;

    I hope you find this useful. If you have any further questions, do not hesitate to write back.

    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top