共用方式為


Accepting Numeric Input in a Given Range

Although you can set the InputMask property and include code in the Valid event to make sure that numeric values entered into text boxes fall within a given range, the easiest way to check the range of values is to use a spinner.

Using Spinners

You can use spinners to make it possible for users to make choices by "spinning" through values or directly typing the values in the spinner box.

Setting the Range of Values that Users Can Choose

Set the KeyboardHighValue and the SpinnerHighValue properties to the highest number you want users to be able to enter in the spinner.

Set the KeyboardLowValue and the SpinnerLowValue properties to the lowest number you want users to be able to enter in the spinner.

Decrementing a Spinner When the User Clicks the Up Button

Sometimes, if your spinner reflects a value like "priority," you want the user to be able to increase the priority from 2 to 1 by clicking the Up button. To cause the spinner number to decrement when the user clicks the Up button, set the Increment property to -1.

Spinning Through Non-Numeric Values

While the value of a spinner is numeric, you can use the Spinner control and a text box to make it possible for users to spin through multiple types of data. For instance, if you want a user to be able to spin through a range of dates, you could size the spinner so that only the buttons are visible and position a text box beside the spinner buttons. Set the Value property of the text box to a date and in the UpClick and DownClick events of the spinner, increment or decrement the date.

Tip   You can use the Windows API function GetSystemMetrics to set the width of your spinner so that only the buttons are visible and the buttons are the best width for the up and down arrow bitmap display.

  • Set the spinner's BorderStyle property to 0.

  • Include the following code in the Init of the spinner:

    DECLARE INTEGER GetSystemMetrics IN Win32api INTEGER
    THIS.Width = GetSystemMetrics(2) && SM_CXVSCROLL
    

Common Spinner Properties

The following spinner properties are commonly set at design time.

Property Description
Increment How much to increment or decrement the value each time the user clicks the Up or Down buttons.
KeyboardHighValue The highest value that can be entered into the spinner text box.
KeyboardLowValue The lowest value that can be entered into the spinner text box.
SpinnerHighValue The highest value that the spinner will display when the user clicks the Up button.
SpinnerLowValue The lowest value that the spinner will display when the user clicks the Down button.

See Also

Using the InputMask Property | Allowing Specific Actions | Using Controls | Performing Specific Actions at Given Intervals | Controls and Objects