New Found Respect for Scrollbar Creation
Earlier this evening I decided to create a scrollbar class for use with Visual FoxPro. My requirements were that it was created purely with Visual FoxPro (didn’t have any ActiveX dependecies) and that it was professional enough for use in a real world Visual FoxPro application. It is now five hours later… the class is complete and I have a new found respect for anyone who successfully creates scrollbars. This turned out to be one of the more difficult challenges I have given myself.
New VFPScrollBar Class Library
I created my scrollbar classes in a class library called vfpscrollbar.vcx. The three classes that are of note are the scrollbarhorizontal, scrollbarvertical, and the sbscrollablecontainer. The sbscrollablecontainer is an example of the types of classes that can be built using the scrollbars.
Properties and Events
The following is a list of notable properties and methods for the scrollbars:
Min – Specifies the minimum value for the scrollbar (defaults to 0)
Max – Specifies the maximum value for the scrollbar (defaults to 500)
Value – The current value of the scrollbar based on the position of the thumb/scroll box
LargeChange – The amount that is added or deducted from the scrollbar’s value when the area between the thumb/scroll box and the scroll arrows is clicked
SmallChange – The amount that is added or deducted from the scrollbar’s value when the scroll arrows are clicked
Change() – This event/method is fired whenever the value of the scrollbar changes
Scroll() – This event/method is fired whenever the user is moving the thumb/scroll box
When placing the scrollbar classes in a container (form or whatever), you can resize the scrollbar making it wider and/or longer. The result at design time may look a little odd (since the scroll arrows and thumb/scroll box don’t resize or reposition themselves at design time, but everything will shape up at runtime. The point is, that you needn’t spend a bunch of time making the scrollbars look good at design time. Just place them, resize and position the main container and run it.
Future Work and Colors
Currently the scrollbars are blue (to match Windows XP theme), but I have my eye towards eventually allowing the scrollbar classes color to be changed either with a single property setting or by checking the user’s current system settings and pulling the color from there. I painstakingly created these scrollbar classes without using any image so that the colors could be easily changed on the fly without additional image resources.
I’ll also be revisiting the code and refactoring portions of it. As it is now, I am burnt out on it (it was a rough five hours to get this thing to work and look right). So, don’t expect a code clinic with this class… I mean it’s not horrible, but I do need to take another pass through it before I will be happy with it.
Suggestions and Bug Reports Welcome
I also want to mention that a few members of the Visual FoxPro Community have started to provide me with feedback, bug fixes and enhancements for the stuff I am posting here on the SPS Weblog. I want you all to know that collaboration, help, feedback, and/or ideas are not only welcomed and appreciated, but are exactly the reason why I post these entries. I don’t want fame or your money… I just want to see the Visual FoxPro Community improve the state of Visual FoxPro and the overall experience for developers that are working in it or companies that may be considering it as a viable option. It is my belief that one of the greatest data-centric development tools ever created deserves nothing less.
Here is the download link for the example project and vfpscrollbar.vcx source as well as a screen shot of the example that shows the scrollbars being used in the scrollable container class.
Download VFP Scrollbars Example and Source (46 KB approx.)