Suppose, I need to perform a resource intensive task with the movement of scroll-bar.
private void hScrollBar_ValueChanged(object sender, EventArgs e)
{
ReCalculate();
}
void ReCalculate()
{
try
{
int n = hScrollBar1.Value;
int f0 = hScrollBar2.Value;
int theta = hScrollBar3.Value;
int a = hScrollBar4.Value;
//... resource-intensive task which uses scroll-bar's values.
}
catch
{
}
}
The problem I am facing is, the event-handler gets executed with the slightest change of the scroll-bar.
I need to block the execution of event-handler until the mouse is released.
So, I tried using mouse-enter and mouse-leave event-handlers like:
bool ready = false;
private void hScrollBars_MouseEnter(object sender, EventArgs e)
{
ready = false;
}
private void hScrollBars_MouseLeave(object sender, EventArgs e)
{
ready = true;
}
along with a checking like:
void ReCalculate()
{
if(ready)
{
try
{
int n = hScrollBar1.Value;
int f0 = hScrollBar2.Value;
int theta = hScrollBar3.Value;
int a = hScrollBar4.Value;
//... resource-intensive task which uses scroll-bar's values.
}
catch
{
}
}
}
But, it doesn't work.
How can I do that?
You can handle Scroll event and check the e.Type and if it was ScrollEventType.EndScroll, run your logic:
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
if (e.Type == ScrollEventType.EndScroll)
{
// Scroll has ended
// You can use hScrollBar1.Value
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With