|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Creating An Updown ControlThe testing department is on the phone again, with an issue about the Print dialog box in your program, SuperDuperTextPro. Why is there a scroll bar next to the Number Of Copies To Print box in the Print dialog box? Well, you say, thats in case the user wants to increment or decrement the number of copies to print. Theres a better control than a scroll bar for that, they saywhat about using an updown control? Whats an updown control? Its a control made up of two buttons next to each other, and each button holds an arrow (each pointing away from the other button). You can use an updown when values should be incremented and decremented, and you want to give the user an easy way to do that. Adding an updown control to a program is easy; just follow these steps:
Private Sub UpDown1_Change()
Text1.Text = 'New setting: " & Str(UpDown1.Value)
End Sub
The result of this code appears in Figure 9.13.
Setting An Updown Controls Minimum And MaximumThe default maximum value for an updown control is 10, and the default minimum is 0. How can you change those? Just set the updowns Max and Min properties as you want them. For example, heres how we set those properties in an updown when it loads:
Private Sub Form_Load()
UpDown1.Min = 0
UpDown1.Max = 100
End Sub
Thats all there is to it. To handle the updown controls events, take a look at the next topic. Handling Updown EventsYouve added an updown control to your programbut how do you connect it to your code? There are three main events you can use: the Change event, the UpClick event, and the DownClick event. The Change event occurs when the user clicks either of the two buttons in the updown. Heres an example; we can report the new setting of an updown when the user clicks a button by catching that action in a Change event handler: Private Sub UpDown1_Change() ... End Sub We can display the updowns new value in a text box, Text1, this way, using the updowns Value property:
Private Sub UpDown1_Change()
Text1.Text = "New setting: " & Str(UpDown1.Value)
End Sub
Besides the Change event, you can also attach event handlers to the updowns UpClick and DownClick events to handle Up/Right button clicks and Down/Left button clicks. Being able to work with the individual buttons this way makes the updown a more versatile control.
|
|
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. |