0

I have a custom TrackBar control from Devexpress

DevExpress.XtraEditorsTrackBarControl

I need to fire some long running Background operation on an image based on the selected value of the TrackBar. But during the selection/dragging process the event should not be fired 20 times for an interval of 20, it should be only fired at the final position.

Currently I follow the following approach

private void trackBar1_MouseUp(object sender, EventArgs e)
{
    value+= trackBar1.Value;
    if ((value> 0) && (newvalue != oldvalue))
    {
        longworker.RunWorkerAsync();
        oldvalue = newvalue;
    }
}

private void trackBar1_EditValueChanged(object sender, EventArgs e)
{
    newvalue = trackBar1.Value;
}

This works well, but the user needs to move the mouse out of the control for the event to fire.
Is there a way to get around this?
This answer: https://stackoverflow.com/a/9221091/848968 provides an approach, but the custom control does not have a scroll event.

Jimi
  • 29,621
  • 8
  • 43
  • 61
techno
  • 6,100
  • 16
  • 86
  • 192

1 Answers1

0

You can check if the current mouse position is outside of your track bar boundaries to perform the necessary code:

private void trackBar1_MouseUp(object sender, EventArgs e) {
   value += trackBar1.Value;
   if(value > 0 && newvalue != oldvalue) {
    longworker.RunWorkerAsync();
    oldvalue = newvalue;
   }
   else if(!trackBar.ClientRectangle.Contains(e.Location)) {
            //your code here
   }
}
Svetlana
  • 421
  • 3
  • 5