SpinButton Control

Description

Increments and decrements numbers.

Remarks

Clicking a SpinButton changes only the value of the SpinButton. You can write code that uses the SpinButton to update the displayed value of another control. For example, you can use a SpinButton to change the month, the day, or the year shown on a date. You can also use a SpinButton to scroll through a range of values or a list of items, or to change the value displayed in a text box.

To display a value updated by a SpinButton, you must assign the value of the SpinButton to the displayed portion of a control, such as the Caption property of a Label or the Text property of a TextBox. To create a horizontal or vertical SpinButton, drag the sizing handles of the SpinButton horizontally or vertically on the form.

The default property for a SpinButton is the Value property.

The default event for a SpinButton is the Change event.

Properties

BackColor property, BoundValue property, ControlSource property, ControlTipText property, Delay property, Enabled property, ForeColor property, Height, Width properties, HelpContextID property, LayoutEffect property, Left, Top properties, Max, Min properties, MouseIcon property, MousePointer property, Name property, Object property, OldHeight, OldWidth properties, OldLeft, OldTop properties, Orientation property, Parent property, SmallChange property, TabIndex property, TabStop property, Tag property, Value property, Visible property.

Methods

Move method, SetFocus method, ZOrder method.

Events

AfterUpdate event, BeforeDragOver event, BeforeUpdate event, Change event, Enter, Exit events, Error event, KeyDown, KeyUp events, KeyPress event, SpinDown, SpinUp events.

See Also

ScrollBar control.

Example

The following example uses the PictureSizeMode property to demonstrate three display options for a picture: showing the picture as is, changing the size of the picture while maintaining its original proportions, and stretching the picture to fill a space.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • A Frame named Frame1.
  • A SpinButton named SpinButton1.
  • A TextBox named TextBox1.
  • Three OptionButton controls named OptionButton1 through OptionButton3.
Note This example is an enhanced version of the PictureAlignment property example, as the two properties complement each other. The enhancements are three OptionButton event subroutines that control whether the image is cropped, zoomed, or stretched.

Dim Alignments(5) As String

Private Sub UserForm_Initialize()
    Alignments(0) = "0 - Top Left"
    Alignments(1) = "1 - Top Right"
    Alignments(2) = "2 - Center"
    Alignments(3) = "3 - Bottom Left"
    Alignments(4) = "4 - Bottom Right"

    'Specify a bitmap that exists on your system
    Frame1.Picture = LoadPicture("c:\winnt2\ball.bmp")

    SpinButton1.Min = 0
    SpinButton1.Max = 4
    SpinButton1.Value = 0

    TextBox1.Text = Alignments(0)
    Frame1.PictureAlignment = SpinButton1.Value

    OptionButton1.Caption = "Crop"
    OptionButton1.Value = True
    OptionButton2.Caption = "Stretch"
    OptionButton3.Caption = "Zoom"
End Sub

Private Sub OptionButton1_Click()
    If OptionButton1.Value = True Then
        Frame1.PictureSizeMode = fmPictureSizeModeClip
    End If
End Sub

Private Sub OptionButton2_Click()
    If OptionButton2.Value = True Then
        Frame1.PictureSizeMode = fmPictureSizeModeStretch
    End If
End Sub

Private Sub OptionButton3_Click()
    If OptionButton3.Value = True Then
        Frame1.PictureSizeMode = fmPictureSizeModeZoom
    End If
End Sub

Private Sub SpinButton1_Change()
    TextBox1.Text = Alignments(SpinButton1.Value)
    Frame1.PictureAlignment = SpinButton1.Value
End Sub

Private Sub TextBox1_Change()
    Select Case TextBox1.Text
    Case "0"
        TextBox1.Text = Alignments(0)
        Frame1.PictureAlignment = 0
    Case "1"
        TextBox1.Text = Alignments(1)
        Frame1.PictureAlignment = 1
    Case "2"
        TextBox1.Text = Alignments(2)
        Frame1.PictureAlignment = 2
    Case "3"
        TextBox1.Text = Alignments(3)
        Frame1.PictureAlignment = 3
    Case "4"
        TextBox1.Text = Alignments(4)
        Frame1.PictureAlignment = 4
    Case Else
        TextBox1.Text = Alignments(SpinButton1.Value)
        Frame1.PictureAlignment = SpinButton1.Value
    End Select
End Sub