Reputation: 1534
I need to monitor the scroll of a FlowLayoutPanel to see if the scroll is dropped in certain ranges, here's and example:
How might I calculate for a dynamic scroll length which number reference the scroll has fallen under?
An example is if the scroll is at 850 then that's a 3, at 450 then that's a 2. Basically each 405 multiplication increases the number.
Here's where I would need to implement the check.
private void ChangedParentFlowPanel_Scroll(object sender, ScrollEventArgs e)
{
int NewPos = e.NewValue;
//Check here to see which multiplication of 405 the NewPos falls under 1,2,3,4....
}
Upvotes: 1
Views: 40
Reputation: 139
private void ChangedParentFlowPanel_Scroll(object sender, ScrollEventArgs e)
{
int NewPos = e.NewValue;
int ScrollCategory = (NewPos - 1) / 405 + 1;
}
I think this would work for what you're trying to do. It's got to be integer division or it won't work, naturally.
Upvotes: 1
Reputation: 236228
Simple integer division will do the job:
int multiplication = (NewPos - 1) / 405 + 1;
I would also recommend you to use named variable instead of magic number 405 to make your code clear for other programmers. And use camelCase names for local variables.
Upvotes: 3