## wxToggleButton

wxToggleButton is a button that stays pressed when clicked by the user. In other words, it is similar to wxCheckBox in functionality but looks like a wxButton.

You can see wxToggleButton in action in the sixth page of the controls sample.

Derived from

wxControl
wxWindow
wxEvtHandler
wxObject

Include files

<wx/tglbtn.h>

Window styles

There are no special styles for wxToggleButton.

See also window styles overview.

Event handling

EVT_TOGGLEBUTTON(id, func) | Handles a toggle button click event.

See also

wxCheckBox, wxButton

Members

wxToggleButton::wxToggleButton
wxToggleButton::~wxToggleButton
wxToggleButton::Create
wxToggleButton::GetValue
wxToggleButton::SetValue

### wxToggleButton::wxToggleButton

wxToggleButton()

Default constructor.

wxToggleButton(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& val, const wxString& name = "checkBox")

Constructor, creating and showing a toggle button.

Parameters

parent

Parent window. Must not be `NULL`.

id

Toggle button identifier. A value of -1 indicates a default value.

label

Text to be displayed next to the toggle button.

pos

Toggle button position. If the position (-1, -1) is specified then a default position is chosen.

size

Toggle button size. If the default size (-1, -1) is specified then a default size is chosen.

style

Window style. See wxToggleButton.

validator

Window validator.

name

Window name.

See also

wxToggleButton::Create, wxValidator

### wxToggleButton::~wxToggleButton

~wxToggleButton()

Destructor, destroying the toggle button.

### wxToggleButton::Create

bool Create(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& val, const wxString& name = "checkBox")

Creates the toggle button for two-step construction. See wxToggleButton::wxToggleButton for details.

### wxToggleButton::GetValue

bool GetValue() const

Gets the state of the toggle button.

Return value

Returns `true` if it is pressed, `false` otherwise.

### wxToggleButton::SetValue

void SetValue(const bool state)

Sets the toggle button to the given state. This does not cause a `EVT_TOGGLEBUTTON` event to be emitted.

Parameters

state

If `true`, the button is pressed.