Windows Develop Bookmark and Share   
 index > Windows Forms General > Why would a slider go backwards?
 

Why would a slider go backwards?

I have a C#2.0 winforms app with a HScrollBar on a form.
The Min is -4096, max is 4096 small increment 1, big increment is 200
(it seemed fine with the increments were 1 and 10, but I was trying to make the thumb bigger)

I position my scrollbar at the max, I click on the down arrow and the value changes to 4095.
I click on the up arrow (expecting the slider to go back to 4096 and get scroll event args with:
Type = ScrollEventType.SmallIncrement
OldValue = 4095
NewValue = 3996

So where is this coming from? Is there some other scroll property I need to set - or do I need to do my own math?
Even if there is some rounding error, if it is an increment but the value is going down, shouldn't that flag an exception or throw an assertion in Microsoft control code?
wayneamurphy  Saturday, October 03, 2009 11:22 PM
The maximum value you can get from a scrollbar by dragging it by hand is Maximum - LargeChange + 1.  In your case: 4096 - 200 + 1 = 3897.  One click down then gives you 3896.  I assume your 3996 was a typo.  So, the real problem was that you initialized the Value property incorrectly.

Hans Passant.
nobugz  Sunday, October 04, 2009 5:05 AM

You can use google to search for other answers

Custom Search

More Threads

• WebBrowser:How to navigate and send values with method post
• How do I set defaults for my combo boxes?
• How to change System DPI programatically (C# Visual Studio 2005)
• H/VScrollBar Scroll Event Issue
• Firing the help requested event from a menu item?
• How to Use .Net Windows Applicaion in Internet Explorer
• save streamed text to file??
• split large code - winforms
• detecting treeview item state change
• is this still needed? dotnetredist.exe for a windows forms /c# app?