# wxSpinCtrl Class Reference
[Controls]

`#include <wx/spinctrl.h>`

Inheritance diagram for wxSpinCtrl:
[legend]

## Detailed Description

wxSpinCtrl combines wxTextCtrl and wxSpinButton in one control.

## Styles

This class supports the following styles:

- wxSP_ARROW_KEYS:
  The user can use arrow keys to change the value.
- wxSP_WRAP:
  The value wraps at the minimum and maximum.
- wxTE_PROCESS_ENTER:
  Indicates that the control should generate `wxEVT_COMMAND_TEXT_ENTER` events. Using this style will prevent the user from using the Enter key for dialog navigation (e.g. activating the default button in the dialog) under MSW.
- wxALIGN_LEFT:
  Same as wxTE_LEFT for wxTextCtrl: the text is left aligned.
- wxALIGN_CENTRE:
  Same as wxTE_CENTRE for wxTextCtrl: the text is centered.
- wxALIGN_RIGHT:
  Same as wxTE_RIGHT for wxTextCtrl: the text is right aligned (this is the default).

## Events emitted by this class

The following event handler macros redirect the events to member function handlers 'func' with prototypes like:

void handlerFuncName(wxSpinEvent& event)
Event macros for events emitted by this class:

- EVT_SPINCTRL(id, func):
  Process a wxEVT_COMMAND_SPINCTRL_UPDATED event, which is generated whenever the numeric value of the spin control is updated.

You may also use the wxSpinButton event macros, however the corresponding events will not be generated under all platforms. Finally, if the user modifies the text in the edit part of the spin control directly, the EVT_TEXT is generated, like for the wxTextCtrl. When the use enters text into the text area, the text is not validated until the control loses focus (e.g. by using the TAB key). The value is then adjusted to the range and a wxSpinEvent sent then if the value is different from the last value sent.

##

Library: wxCore

Category: Controls
Appearance:

wxMSW appearance | wxGTK appearance | wxMac appearance

See also:
  wxSpinButton, wxSpinCtrlDouble, wxControl

## Public Member Functions
| wxSpinCtrl ()
| Default constructor.
| wxSpinCtrl (wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &value=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxSP_ARROW_KEYS, int min=0, int max=100, int initial=0, const wxString &name="wxSpinCtrl")
| Constructor, creating and showing a spin control.
bool | Create (wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &value=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxSP_ARROW_KEYS, int min=0, int max=100, int initial=0, const wxString &name="wxSpinCtrl")
| Creation function called by the spin control constructor.
int | GetMax () const
| Gets maximal allowable value.
int | GetMin () const
| Gets minimal allowable value.
int | GetValue () const
| Gets the value of the spin control.
void | SetRange (int minVal, int maxVal)
| Sets range of allowable values.
virtual void | SetSelection (long from, long to)
| Select the text in the text part of the control between positions from (inclusive) and to (exclusive).
virtual void | SetValue (const wxString &text)
| Sets the value of the spin control.
void | SetValue (int value)
| Sets the value of the spin control.

List of all members.

## Constructor & Destructor Documentation

wxSpinCtrl::wxSpinCtrl | ( |  | ) |

Default constructor.

wxSpinCtrl::wxSpinCtrl | ( | wxWindow * | parent,
|  | wxWindowID | id = `wxID_ANY`,
|  | const wxString & | value = `wxEmptyString`,
|  | const wxPoint & | pos = `wxDefaultPosition`,
|  | const wxSize & | size = `wxDefaultSize`,
|  | long | style = `wxSP_ARROW_KEYS`,
|  | int | min = `0`,
|  | int | max = `100`,
|  | int | initial = `0`,
|  | const wxString & | name = `"wxSpinCtrl"` |
| ) |  |  |

Constructor, creating and showing a spin control.

Parameters:

  | parent | Parent window. Must not be NULL.
  | value | Default value (as text).
  | id | Window identifier. The value wxID_ANY indicates a default value.
  | pos | Window position. If wxDefaultPosition is specified then a default position is chosen.
  | size | Window size. If wxDefaultSize is specified then a default size is chosen.
  | style | Window style. See wxSpinButton.
  | min | Minimal value.
  | max | Maximal value.
  | initial | Initial value.
  | name | Window name.

See also:
  Create()

## Member Function Documentation

bool wxSpinCtrl::Create | ( | wxWindow * | parent,
|  | wxWindowID | id = `wxID_ANY`,
|  | const wxString & | value = `wxEmptyString`,
|  | const wxPoint & | pos = `wxDefaultPosition`,
|  | const wxSize & | size = `wxDefaultSize`,
|  | long | style = `wxSP_ARROW_KEYS`,
|  | int | min = `0`,
|  | int | max = `100`,
|  | int | initial = `0`,
|  | const wxString & | name = `"wxSpinCtrl"` |
| ) |  |  |

Creation function called by the spin control constructor.

See wxSpinCtrl() for details.

int wxSpinCtrl::GetMax | ( |  | ) | const

Gets maximal allowable value.

int wxSpinCtrl::GetMin | ( |  | ) | const

Gets minimal allowable value.

int wxSpinCtrl::GetValue | ( |  | ) | const

Gets the value of the spin control.

void wxSpinCtrl::SetRange | ( | int | minVal,
|  | int | maxVal |
| ) |  |  |

Sets range of allowable values.

virtual void wxSpinCtrl::SetSelection | ( | long | from,
|  | long | to |
| ) |  |  | `[virtual]`

Select the text in the text part of the control between positions from (inclusive) and to (exclusive).

This is similar to wxTextCtrl::SetSelection().

Note:
  this is currently only implemented for Windows and generic versions of the control.

void wxSpinCtrl::SetValue | ( | int | value | ) |

Sets the value of the spin control.

virtual void wxSpinCtrl::SetValue | ( | const wxString & | text | ) | `[virtual]`

Sets the value of the spin control.

Use the variant using int instead.

|  | [ top ]