假设,我需要通过滚动条的移动来执行资源密集型任务。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 { }}我面临的问题是,事件处理程序会随着滚动条的微小变化而执行。我需要阻止事件处理程序的执行,直到释放鼠标。因此,我尝试使用 mouse-enter 和 mouse-leave 事件处理程序,例如:bool ready = false;private void hScrollBars_MouseEnter(object sender, EventArgs e){ ready = false;}private void hScrollBars_MouseLeave(object sender, EventArgs e){ ready = true;}以及像这样的检查: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 { } }}但是,它不起作用。我怎样才能做到这一点?
1 回答
慕斯王
TA贡献1864条经验 获得超2个赞
您可以处理Scroll事件并检查e.Type,如果是ScrollEventType.EndScroll,则运行您的逻辑:
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
if (e.Type == ScrollEventType.EndScroll)
{
// Scroll has ended
// You can use hScrollBar1.Value
}
}
- 1 回答
- 0 关注
- 113 浏览
添加回答
举报
0/150
提交
取消