Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for TrackBar sliding with mouse hold and release

I have a trackbar in my WinForms program which by moving it a huge and time consuming method will be refreshed. Have a look at this code:

trackBar_ValueChanged(object sender, EventArgs e)
{
     this.RefreshData();
}

This track bar has 20 steps. If user grab the trackbar's slider and pull it from 20 to 0 in my case, 'RefreshData' will be executed 20 times although it shows correct data when it ends the process that is 'RefreshData' with value 0, I want to do something like it only calls the 'RefreshData' when the trackBar slider has been released so it wont process all the steps to the releasing point on the track bar.

Any help and tips to achieve this would be appericiated! Thanks.

like image 428
Saeid Yazdani Avatar asked Dec 09 '25 23:12

Saeid Yazdani


1 Answers

How About:

Boolean user_done_updating = false;

private void MytrackBar_ValueChanged(object sender, EventArgs e)
{
    user_done_updating = true;
}

private void MytrackBar_MouseUp(object sender, MouseEventArgs e)
{
    if (user_done_updating)
    {
        user_done_updating = false;
        //Do Stuff
    }
}
like image 195
Volkan Sen Avatar answered Dec 11 '25 13:12

Volkan Sen