DateTimeRangeTrackBar Selection Changed Event

Jan 23, 2013 at 8:12 AM

Hi,

I am using DateTimeRangeTrackBar in my window form (c#) application.

I am handling SelectionChanged Event to read the SelectedMinimum and SelectedMaximum values.

This event actually fires every time we dragging (not dragged) the trackbar to new value and thus cause execution of code under this event to run number of times.

I wanna something like this event should fire only after user completely dragged the trackbar to desired value and release the mouse right button from trackbar.

Is it possible ?

Jan 23, 2013 at 3:37 PM
Edited Jan 23, 2013 at 3:38 PM

That's a common problem, where for performance reasons you don't want to respond every time a control fires some sort of "change" event.  The way I've solved this is to start a timer when the "change" event fires, and to restart the timer if the event fires again.  It's only when the timer fires its Tick event that you perform your actual task.

If you set the Timer.Interval to 1,000 ms, for example, and twenty "change" events fire less than 1,000 ms apart, then you will end up ignoring the first nineteen events, and getting a Timer.Tick event 1,000 ms after the twentieth "change" event fires.  This will give you the behavior I think you want.

For an example of this, see the DynamicFiltersDialog.cs class in the NodeXL source code, which as of today can be found here:

http://nodexl.codeplex.com/SourceControl/changeset/view/70521#361598

The timer is called m_oChangeEventDelayTimer in the source code, and the explanatory comments can be found in the RangeTrackBar_SelectedRangeChanged() method.

Be sure to use the correct timer, as there are many timer classes in the .NET Framework.  In a Windows Forms application, you want a System.Windows.Forms.Timer.

-- Tony