|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Creating Slider ControlsThe Aesthetic Design Department is on the phone again. Theyve heard about slider controls in Visual Basic and like their look. Is there any way you can add them to your program, SuperDuperTextPro? Adding a slider to a program is easy; just follow these steps:
Running this program yields the result you see in Figure 9.8. Now were using sliders in Visual Basic.
Setting A Sliders OrientationLike scroll bars, sliders can be horizontal or vertical, but unlike scroll bars, horizontal and vertical sliders are not two different controls. Instead, you set a sliders Orientation property to make it horizontal or vertical. You can set the Orientation at design time or run-time; this property takes these values:
Can you change a sliders orientation in code? You certainly can. In this example, we make a sliders orientation vertical when the user clicks a button:
Private Sub Command1_Click()
Slider1.Orientation = ccOrientationVertical
End Sub
Setting A Sliders RangeYouve added a new slider to your environment control program to let users set the temperature they want in their homes, but now they have a complaint. Why does the slider return values of up to 32,767 degrees? Its time to reset the sliders range of possible values, and you use the Min (default value 0) and Max (default value 10) properties to do that. You can set a sliders range at design time or runtime. For example, heres how we set a sliders range to a more reasonable span of temperatures:
Private Sub Form_Load()
Slider1.Max = 90
Slider1.Min = 50
End Sub
After setting the Min and Max properties, youll probably want to set the sliders tick frequency so the ticks on the sliders scale look appropriate for the new range (see Adding Ticks to a Slider in this chapter). Setting Up Slider Groove ClicksBesides dragging the knob along the groove in a slider, you can click the groove itself to move the knob (just as you can click the area of a scroll bar between the thumb and arrow buttons). The amount the knob moves each time the user clicks the groove is set with the sliders LargeChange property (just as it is in scroll bars). The default value for this property is 5. You can set the LargeChange property at design time or runtime. For example, heres how we set a sliders LargeChange property to 5 when the form containing the slider first loads:
Private Sub Form_Load()
Slider1.Max = 255
Slider1.Min = 0
Slider1.LargeChange = 5
End Sub
If you change a sliders range of possible values (in other words, the Min and Max properties), keep in mind that you might also have to change the LargeChange property as well. For example, if you change the possible range of slider values from 0 to 32767 to 1 to 100 but leave LargeChange at 4096, theres going to be a problem when the user clicks the sliders groove.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |