Mike Trethowan

Pen Truth Contributor

I had to post this quick tip because I have seen so many drawn out explanations and overly complicated code to resolve this problem, (people think too much.)   Visual Studio has Scroll Bars in the Tool Box.  The Problem: What is left out of the properties is the ability to reverse the direction of the action, meaning the value change direction.

This is a simple math solution that requires no complicated coding.  Ready?  Let’s say you have a vertical scroll bar on your form with a range of 0 to 100.  The problem is that as you scroll from bottom to top, the output value decreases.  Not what you want if you are creating a volume or lighting control.

The solution is simple, so simple that you will not believe you figured it out sooner, we all over think the simple problems…  Subtract the value from 100.  This works for both directions so you don’t need code for each direction.  Here is an example for both types of scroll bars.

desiredValue = 100 - VScrollBar1.value
desiredValue = 100 - HScrollBar1.value

Remember the old adage; “K.I.S.S.” Keep It Simple Stupid, and Happy Coding.

Disclaimer: The code in this tutorial is not intended as a final product or by no means the only way this project can be coded. The presented code is for educational purposes only and no warranty is granted or implied. I/we are not responsible for any damages as a result of using this code. Use at your own risk.