Click here to Skip to main content
15,887,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am programmatically setting the positions on a scrollbar and have the following code where p_Panel has autoscroll set to true, everything else works fine on it.

VB
pos_hor = equation here
 p_Panel.HorizontalScroll.Value = pos_hor

pos_ver = equation here
 p_Panel.VerticalScroll.Value = pos_ver

the horizontalscroll value writes fine, watching it the pos_ver value calculates fine, is an integer,... but the verticalscroll value doesn't write? Really weird is that if i simply repeat the line again as in

VB
p_Panel.VerticalScroll.Value = pos_ver
p_Panel.VerticalScroll.Value = pos_ver


it works great, writes the value and no issues?? What's going on, any ideas?
Posted
Updated 12-Apr-12 14:09pm
v2
Comments
Nelek 12-Apr-12 20:09pm    
added code tags
walterhevedeich 12-Apr-12 20:19pm    
Might have something to do with the value of your pos_hor. Have you tried debugging it? Does pos_hor had the expected value?
Makulais 13-Apr-12 9:45am    
thanks Nelek, still new here.

pos_hor does give the expected value, as does pos_ver, both values are positive and in the appropriate range. the p_Panel.HorizontalScroll.Value = pos_hor statement works fine, it positions the scroll correctly and works every time. Not sure what you mean by debugging it? I step through it, pos_ver is assigned the correct value, but the assignment to p_Panel.VerticalScroll.Value fails, there is no error given, it just steps through it acting as if it worked fine, but the value doesn't change. I move the cursor back up and run the assignment again, it works. That's why i ended up putting the statement in it twice.

(did i put the code tags in correctly?)
TRK3 13-Apr-12 17:25pm    
Sounds pretty odd. What exactly is p_Panel? Is it a standard microsoft class, or some class you wrote?

It could be that VerticalScroll is just a .NET wrapper for a Win32 scrollbar and what happens when you set the value is that a message gets posted to the scrollbar -- so that the update doesn't actually occur when you do the set, but whenever the scrollbar processes it's message queue.

I've run into something similar before in a third party control I was using and I ended up just setting the value twice since I wasn't able to debug what was happening in the control and setting it twice didn't seem to do any harm... (If you do that, be sure to put a big comment in the code explaining why you are doing it.)
Makulais 14-Apr-12 10:28am    
TRK3, i thought the same thing. It's a standard Microsoft Panel class, and it is the only panel on the form, and in the project for that matter.

I believe I understand your point on the update, I guess I can try different things to see if it updates it, guess i could swap them and see if the problem swaps with them? I might just do what you said also, big comment, let it go, just wanted to make sure I wasn't doing something wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900