Welcome to AddressOf.com Sign in | Join | Help

Bug? Feature? You be the judge...

While working on the xbox friends thing, I decided to create a clone of the user interface that Windows Messenger uses.  It's sort of like a treeview (or group box) and has a vertical scrollbar visible when the list is larger than the displayable area.

So, I add a vertical scrollbar to the control and make it visible when the need arises.  Easy enough.

Now for the problem.  When I set the Maximum to the number of items in the display and scroll all the way to the bottom of the scrollbar I don't get the Maximum value.  I get some other value.  For example, if there are 41 people in the list separated into three groups, I should have 44 lines to display.  If my view can only handle 15 then I need the scrollbar.  I set the Maximum to 44.  When I scroll to the bottom, it gives me 35??????

After playing with this for a while, I determined what was happening.  The Maximum value is not what will be returned by Value when the scrollbar is at maximum.  The maximum Value is (Maximum - LargeChange) + 1.  Hmmm... that didn't seem right... so I launched VB6 and setup a little test.  Yup, in VB6 it gives maximum value is Max; LargeChange doesn't come into play at all.  So my memory was serving me correctly.

OK, so maybe it changed in .NET.  Time to look at the documentation.  For LargeChange it states the following:

Gets or sets a value to be added to or subtracted from the Value property when the scroll box is moved a large distance.

and in the remarks section:

When the user presses the PAGE UP or PAGE DOWN key or clicks in the scroll bar track on either side of the scroll box, the Value property changes according to the value set in the LargeChange property.

Hmmm... pretty much was I expected and sounds like the same thing VB6 would say.  It doesn't say anything about LargeChange coming into play when returning what the maximum value will be.  It just says that LargeChange determines how much the change will be if you page up, page down or click in the scrollbar area around the position indicator.

Now, I'm not saying this is a bad thing.  If you set the LargeChange to a value that represents how many items can be displaying; you won't have to make any further calculations in order to get the display to show the Maximum - displayItems (meaning, you won't have only one item showing in the list; always having a full display).

However, if this is a bug, then I'm concerned if I write my code this way and moving forward to Whidbey; if they 'fix' it, then my code will stop working.  If it's not a bug, then the documentation needs to be updated accordingly.

I also posted this to the Windows Forms.com Forum about a week ago and haven't gotten a response (8 views, but no response). :-(

So, now I leave it up to you to decide.  Is this a Bug?  or a Feature?

[update] I guess I should have dug a little deeper into the documentation.  If you look at the Note in the Remarks sections for Maximum, it states the following:

Note   The value of a scroll bar cannot reach its maximum value through user interaction at run time. The maximum value that can be reached is equal to the Maximum property value minus the LargeChange property value plus one. The maximum value can only be reached programmatically.

So it is by design.  I guess I would have expected the same note to be in the LargeChange documentation as well.  So, if there is a 'bug', then it's in the documentation.  Also, the upgrade wizard doesn't point out this fact either.  I tested using some code in the Change event to display the values of Maximum, LargeChange and Value.  Here's what it looks like after the upgrade wizard.

'UPGRADE_NOTE: VScroll1.Change was changed from an event to a procedure. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2010"'
'UPGRADE_WARNING: VScrollBar event VScroll1.Change has a new behavior. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2065"'
Private Sub VScroll1_Change(ByVal newScrollValue As Integer)
  Me.Text = (VScroll1.Maximum - VScroll1.LargeChange + 1) & "," & VScroll1.LargeChange & "," & newScrollValue
End Sub

It just lets you know about the Change event, nothing about Maximum/LargeChange changing behavior.  So, my suggestion to the VB.NET team, add the same note to the LargeChange property and update the upgrade wizard to point out about the this change in behavior between VB6 and VB.NET.

Thanks to Prashanth for pointing me to the Longhorn SDK documentation.  After looking at the LargeChange property (which still does not have this note), I decided to just take a look at Maximum to see if it had changed.  Sure enough, the note block will smack you in the face.  So I jumped into Visual Studio to see if Maximum had the same note.  It does, but doesn't quite jump out at you like the Longhorn docs do; but hey, at least now I know that it's not a bug ;-)

Published Monday, March 01, 2004 8:29 PM by CorySmith

Comments

# re: Bug? Feature? You be the judge...

Wednesday, March 03, 2004 2:30 AM by Prashanth
Well, purely from a functional perspective this seems like a feature to me...since when an application loads one gets to see at least one 'page' of data, hence the effective range is reduced by that factor.
I have looked at the longhorn preliminary here:
http://longhorn.msdn.microsoft.com/?//longhorn.msdn.microsoft.com/lhsdk/ref/ns/System.Windows.Forms/c/ScrollBar/ScrollBar.aspx and the documentation is largely unchanged with regards to largechange, max and min.
So i guess if this is a 'bug' its here to stay :)

# re: Bug? Feature? You be the judge...

Wednesday, November 10, 2004 12:20 PM by Dave
It's a bug.
The end user cannot get to the largest possible value so if you are using the scrollbar to drive some range of values you have to set an incorrect maximum or a largechange of 1. Either way it is not intuitively obvious and will require coding.
As noted above, the upgrade wizard does not mention this so it's fairly obvious that the developers and the documenters were not on speaking terms.

# Maximum == Maximum - LargeChange + 1 !?!?

Tuesday, November 30, 2004 1:35 PM by Jørn
This was so "obvious wrong" that I've spent half a day trying to find the error in my code. And in the end it turns out that it's a "smart" feature...

Do they really think this feature makes it that much easier than the old way of writing Maximum = NumberOfRows - RowsToDisplay for example?! We are NOT end users, we are programmers! Show us some respect! (Also this complicates things if RowsToDisplay != LargeChange...)

Have they considered the complications for people converting old VB code to .Net?


Finished letting out some steam now... ;)

# re: Bug? Feature? You be the judge...

Wednesday, December 08, 2004 6:00 AM by Alan
If its a feature it is a dumb one. I use scroll bars for scrolling graphics and not being able to get to .max is a pain. If I set .LargeChange to 1, I scroll 1 pixel at a time (sooo slooo). So I just have to put all these (+ .LargeChange - 1) code snippets everywhere. There are other backward steps in the scroll bar compared to VB6 as well. The .max value can no longer be set to less than the .min value without clobbering .LargeChange and resetting the .max/.min value you don't set. For graphics scrollers the behavior of the VB6 scroll bar when you set max to less than min was very useful.

# re: Bug? Feature? You be the judge...

Thursday, December 16, 2004 9:08 PM by Peter
The horizontal scrollbar now has minimum on the right rather than the left. Different to vb-6 and makes movement sense different to vertical scrollbar and auto-scrollbars. Bug or feature?

# re: Bug? Feature? You be the judge...

Saturday, January 15, 2005 11:42 PM by Tim
Bug. Maybe it works better in ADO.NET, but for zooming graphics it is quite annoying. A workaround is set your Maximum to 109, LargeChange to 10 and treat it as 0-100(%).

# re: Bug? Feature? You be the judge...

Friday, October 14, 2005 10:54 AM by robbert
depends on whet you are building.
if you want to show a picture in a window that is too small, and you know this 'feature', this is just perfect. suppose windowheight 80, pictureheight 100. Then: .maximum=100, .largechange=80, and set top of picture = -.value!

Otherwise it stinks.

# re: Bug? Feature? You be the judge...

Friday, February 17, 2006 12:48 AM by Ben Griffiths
It's a feature that just cost me two hours of my life; I assumed it was something wrong with my code. Not happy.

# re: Bug? Feature? You be the judge...

Friday, March 10, 2006 1:40 PM by Rich
I only wasted one hour on this, thanks for posting about this 'feature' or i would have gone insane!

# re: Bug? Feature? You be the judge...

Thursday, March 16, 2006 8:42 AM by Eliot Powell
This seems totally crazy to me. Not to mention a waste of time. Ridiculous.

# re: Bug? Feature? You be the judge...

Wednesday, March 22, 2006 1:58 PM by Plume
oh crap. 2 years later and this so called 'feature' has made another victim !

I wasted two hours before finding this page, thanks for the infos.

# re: Bug? Feature? You be the judge...

Wednesday, March 22, 2006 5:47 PM by Fred Steffen
Thank you VERY much for posting this information! I'm using the scrollbar to scroll a custom painted calendar control. We've got a VERY aggressive schedule (imagine that :) and I had to leave this "feature" in the last push, as I didn't have time to figure out what the end increment was. Since the size of the calendar changes depending on the "timeScale", it was hard to get the "function" I'd need to fix the problem. Now that I know, it's fixed... Looks lame as hell, but it works now :)

I think I'll hit your MSDN post and see if more voices will help :)

F~

# re: Bug? Feature? You be the judge...

Saturday, April 01, 2006 7:29 AM by Andi
" The maximum value that can be reached is equal to the Maximum property value minus the LargeChange property value plus one". Try to change LargeChange property to 0. The formula doesn't work.

# re: Bug? Feature? You be the judge...

Saturday, April 01, 2006 7:29 AM by Andi
" The maximum value that can be reached is equal to the Maximum property value minus the LargeChange property value plus one". Try to change LargeChange property to 0. The formula doesn't work.

# re: Bug? Feature? You be the judge...

Friday, May 05, 2006 8:44 PM by Robert Suave Chavez
I tried teaching the scroll bar in class and was suprised with the result.

I new I wasn't loosing it because I had taught scroll bars since VB2. I'd call it a bug!

thanks for your posting

# re: Bug? Feature? You be the judge...

Tuesday, December 19, 2006 3:06 PM by Lrns

Well, its easy to fix this issue..

just add (largechange-1) to the max

so if you want the max to be.. lets say .. 200

and your largechange is 10

make the max 209, and it'll go from 0 to 200 just fine

# re: Bug? Feature? You be the judge...

Thursday, January 25, 2007 2:36 AM by Gary Le Sueur

Thank you for posting about this. I was on the verge of crying (or launching pc out window).

I think its a mistake. They should have kept the original control for upgrade purposes then created a new "smart" scrollbar.

An hour of my life I wont get back :)

# re: Bug? Feature? You be the judge...

Wednesday, August 08, 2007 4:29 AM by Wolfgang Sievers
it is a bug but the cosequences to change it without influences in many programms is great. a new one with the feature to show the actual value over the scrollbar (transparent) would be great

# re: Bug? Feature? You be the judge...

Monday, September 10, 2007 12:10 PM by Phil
It's a bug, and it's cost me a couple of hours of my life too. Note that this behavior (using WinXP and Visual Studio 2003) is different from the minimum side of the scroll bar. For example, I set minimum=1, maximum=100, smallchange=1 and largechange=100. I can click my way to 1 but can't get above 96 on the upper end. I've also solved it by editing my maximum to 105.
Anonymous comments are disabled