This is a migrated thread and some comments may be shown as answers.

RadTrackBar with threshold

1 Answer 57 Views
TrackBar
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 31 May 2012, 07:49 PM

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?

Thanks

1 Answer, 1 is accepted

Sort by
0
Ivan Todorov
Telerik team
answered on 05 Jun 2012, 01:49 PM
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()
{
    InitializeComponent();
    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;
                this.radTrackBar1.PerformLayout();
            }
        }
    }
}

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

Regards,
Ivan Todorov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
TrackBar
Asked by
Matthew
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Share this question
or