xtd.forms - Reference Guide  0.1.0
Modern c++17 library containing classes for creating Windows-based applications that take full advantage of the rich user interface features available in the Microsoft Windows, Apple macOS and Linux like Ubuntu operating system.
xtd::forms::button Class Reference

Represents a Windows button control. More...

#include <button.hpp>

Inheritance diagram for xtd::forms::button:
xtd::forms::ibutton_control xtd::forms::button_base xtd::forms::control xtd::forms::component xtd::forms::iwin32_window

Public Member Functions

 button ()=default
 Initializes a new instance of the Button class. More...
 
virtual forms::auto_size_mode auto_size_mode () const
 Gets the mode by which the button automatically resizes itself. More...
 
virtual buttonauto_size_mode (forms::auto_size_mode value)
 Sets the mode by which the button automatically resizes itself. More...
 
forms::dialog_result dialog_result () const override
 Gets the value returned to the parent form when the button is clicked. More...
 
controldialog_result (forms::dialog_result dialog_result) override
 Sets the value returned to the parent form when the button is clicked. More...
 
button_baseimage (const drawing::image &value) override
 
drawing::size measure_control () const override
 Measure this control. More...
 
void notify_default (bool value) override
 Notifies a control that it is the default button so that its appearance and behavior is adjusted accordingly. More...
 
void perform_click () override
 Generates a click event for the control. More...
 
- Public Member Functions inherited from xtd::forms::button_base
bool auto_ellipsis () const
 Gets a value indicating whether the ellipsis character (...) appears at the right edge of the control, denoting that the control text extends beyond the specified length of the control. More...
 
virtual button_baseauto_ellipsis (bool auto_ellipsis)
 Sets a value indicating whether the ellipsis character (...) appears at the right edge of the control, denoting that the control text extends beyond the specified length of the control. More...
 
bool auto_size () const override
 Gets a value that indicates whether the control resizes based on its contents. More...
 
controlauto_size (bool auto_size) override
 Sets a value that indicates whether the control resizes based on its contents. More...
 
virtual const drawing::imageimage () const
 
virtual content_alignment image_align () const
 Gets the alignment of the image on the button control. More...
 
virtual button_baseimage_align (content_alignment value)
 Gets the alignment of the image on the button control. More...
 
virtual int32_t image_index () const
 
virtual button_baseimage_index (int32_t value)
 
virtual const forms::image_listimage_list () const
 
virtual button_baseimage_list (const forms::image_list &value)
 
virtual content_alignment text_align () const
 Gets the alignment of the text on the button control. More...
 
virtual button_basetext_align (content_alignment value)
 Gets the alignment of the text on the button control. More...
 
- Public Member Functions inherited from xtd::forms::control
 control ()
 Initializes a new instance of the Control class with default settings. More...
 
 control (const ustring &text)
 Initializes a new instance of the control class with specific text. More...
 
 control (const control &parent, const ustring &text)
 nitializes a new instance of the control class as a child control, with specific text. More...
 
 control (const ustring &text, int32_t left, int32_t top, int32_t width, int32_t height)
 Initializes a new instance of the control class with specific text, size, and location. More...
 
 control (const control &parent, const ustring &text, int32_t left, int32_t top, int32_t width, int32_t height)
 Initializes a new instance of the control class as a child control, with specific text, size, and location. More...
 
virtual anchor_styles anchor () const
 Gets the edges of the container to which a control is bound and determines how a control is resized with its parent. More...
 
virtual controlanchor (anchor_styles anchor)
 Gets the edges of the container to which a control is bound and determines how a control is resized with its parent. More...
 
virtual drawing::point auto_scroll_point () const
 Gets where this control is scrolled to in scroll_control_into_view(control). More...
 
virtual drawing::color back_color () const
 Gets the background color for the control. More...
 
virtual controlback_color (const drawing::color &color)
 Sets the background color for the control. More...
 
virtual int32_t bottom () const
 Gets the distance, in pixels, between the bottom edge of the control and the top edge of its container's client area. More...
 
virtual drawing::rectangle bounds () const
 Gets the size and location of the control including its nonclient elements, in pixels, relative to the parent control. More...
 
virtual controlbounds (const drawing::rectangle &bounds)
 Sets the size and location of the control including its nonclient elements, in pixels, relative to the parent control. More...
 
virtual bool can_focus () const
 Gets a value indicating whether the control can receive focus. More...
 
bool can_raise_events () const override
 Determines if events can be raised on the control. More...
 
virtual bool can_select () const
 Gets a value indicating whether the control can be selected. More...
 
virtual const drawing::rectangleclient_rectangle () const
 Gets the rectangle that represents the client area of the control. More...
 
virtual const drawing::sizeclient_size () const
 Gets the height and width of the client area of the control. More...
 
virtual controlclient_size (const drawing::size &client_size)
 Sets the height and width of the client area of the control. More...
 
virtual ustring compagny_name () const
 Gets the name of the company or creator of the application containing the control. More...
 
virtual control_collectioncontrols ()
 Gets the collection of controls contained within the control. More...
 
virtual const control_collectioncontrols () const
 Gets the collection of controls contained within the control. More...
 
void create_control ()
 
drawing::graphics create_graphics () const
 
virtual void create_handle ()
 
virtual bool created ()
 Gets a value indicating whether the control has been created. More...
 
virtual forms::cursor cursor () const
 
virtual controlcursor (const forms::cursor &cursor)
 
virtual drawing::color default_back_color () const
 Gets the default background color of the control. More...
 
virtual forms::cursor default_cursor () const
 
virtual drawing::font default_font () const
 
virtual drawing::color default_fore_color () const
 
void destroy_control ()
 
virtual void destroy_handle ()
 
virtual drawing::rectangle display_rectangle () const
 
virtual dock_style dock () const
 Gets or sets which control borders are docked to its parent control and determines how a control is resized with its parent. More...
 
virtual controldock (dock_style dock)
 
virtual bool enabled () const
 
virtual controlenabled (bool enabled)
 
bool focus ()
 
virtual bool focused () const
 
virtual drawing::font font () const
 
virtual controlfont (const drawing::font &font)
 
virtual drawing::color fore_color () const
 
virtual controlfore_color (const drawing::color &color)
 
intptr_t handle () const override
 Gets the handle to the window represented by the implementer. More...
 
virtual int32_t height () const
 
virtual controlheight (int32_t height)
 
virtual void hide ()
 
virtual void invalidate () const
 
virtual void invalidate (bool invalidate_children) const
 
virtual void invalidate (const drawing::rectangle &rect) const
 
virtual void invalidate (const drawing::rectangle &rect, bool invalidate_children) const
 
void invoke (delegate< void(std::vector< std::any >)> value, const std::vector< std::any > &args)
 
void invoke (delegate< void()> value)
 
bool is_handle_created () const
 
virtual int32_t left () const
 
virtual controlleft (int32_t left)
 
virtual drawing::point location () const
 
virtual controllocation (const drawing::point &location)
 
virtual const ustringname () const
 
virtual controlname (const ustring &name)
 
virtual std::optional< control_refparent () const
 
virtual controlparent (const control &parent)
 
virtual controlparent (std::nullptr_t)
 
void perform_layout ()
 Forces the control to apply layout logic to all its child controls. More...
 
xtd::drawing::point point_to_client (const xtd::drawing::point &p)
 
xtd::drawing::point point_to_screen (const xtd::drawing::point &p)
 
virtual ustring product_name () const
 
bool recreating_handle () const
 
virtual void refresh () const
 
void resume_layout ()
 Resumes usual layout logic. More...
 
void resume_layout (bool perform_layout)
 Resumes usual layout logic, optionally forcing an immediate layout of pending layout requests. More...
 
virtual int32_t right () const
 
intptr_t send_message (intptr_t hwnd, int32_t msg, intptr_t wparam, intptr_t lparam) const
 
void set_auto_size_mode (auto_size_mode auto_size_mode)
 
void set_bounds (int32_t x, int32_t y, int32_t width, int32_t height)
 
void set_bounds (int32_t x, int32_t y, int32_t width, int32_t height, bounds_specified specified)
 
virtual void show ()
 
virtual drawing::size size () const
 
virtual controlsize (const drawing::size &size)
 
void suspend_layout ()
 Temporarily suspends the layout logic for the control. More...
 
virtual std::any tag () const
 Gets the object that contains data about the control. More...
 
virtual controltag (std::any tag)
 Sets the object that contains data about the control. More...
 
virtual const ustringtext () const
 
virtual controltext (const ustring &text)
 
virtual ustring to_string () const
 
virtual int32_t top () const
 
virtual controltop (int32_t top)
 
virtual std::optional< control_reftop_level_control () const
 
virtual void update () const
 
virtual bool visible () const
 
virtual controlvisible (bool visible)
 
virtual int32_t width () const
 
virtual controlwidth (int32_t width)
 

Protected Member Functions

forms::create_params create_params () const override
 Gets a create_params on the base class when creating a window. More...
 
void on_click (const event_args &e) override
 Raises the Click event. More...
 
void on_handle_created (const event_args &e) override
 
void wnd_proc (message &message) override
 Processes Windows messages. More...
 
- Protected Member Functions inherited from xtd::forms::button_base
 button_base ()
 Initializes a new instance of the ButtonBase class. More...
 
forms::create_params create_params () const override
 Gets the required creation parameters when the control handle is created. More...
 
drawing::size default_size () const override
 Gets the default size of the control. More...
 
drawing::size measure_control () const override
 Measure this control. More...
 
- Protected Member Functions inherited from xtd::forms::control
virtual void def_wnd_proc (message &message)
 
bool get_style (control_styles flag) const
 Retrieves the value of the specified control style bit for the control. More...
 
drawing::size measure_text () const
 
virtual void on_auto_size_changed (const event_args &e)
 
virtual void on_back_color_changed (const event_args &e)
 
virtual void on_client_size_changed (const event_args &e)
 
virtual void on_control_added (const control_event_args &e)
 
virtual void on_control_removed (const control_event_args &e)
 
virtual void on_create_control ()
 
virtual void on_cursor_changed (const event_args &e)
 
virtual void on_dock_changed (const event_args &e)
 
virtual void on_double_click (const event_args &e)
 
virtual void on_enabled_changed (const event_args &e)
 
virtual void on_font_changed (const event_args &e)
 
virtual void on_fore_color_changed (const event_args &e)
 
virtual void on_got_focus (const event_args &e)
 
virtual void on_handle_destroyed (const event_args &e)
 
virtual void on_key_down (key_event_args &e)
 
virtual void on_key_press (key_press_event_args &e)
 
virtual void on_key_up (key_event_args &e)
 
virtual void on_layout (const event_args &e)
 
virtual void on_location_changed (const event_args &e)
 
virtual void on_lost_focus (const event_args &e)
 
virtual void on_mouse_click (const mouse_event_args &e)
 
virtual void on_mouse_double_click (const mouse_event_args &e)
 
virtual void on_mouse_down (const mouse_event_args &e)
 
virtual void on_mouse_enter (const event_args &e)
 
virtual void on_mouse_horizontal_wheel (const mouse_event_args &e)
 
virtual void on_mouse_leave (const event_args &e)
 
virtual void on_mouse_move (const mouse_event_args &e)
 
virtual void on_mouse_up (const mouse_event_args &e)
 
virtual void on_mouse_wheel (const mouse_event_args &e)
 
virtual void on_paint (paint_event_args &e)
 
virtual void on_parent_back_color_changed (const event_args &e)
 
virtual void on_parent_changed (const event_args &e)
 
virtual void on_parent_cursor_changed (const event_args &e)
 
virtual void on_parent_font_changed (const event_args &e)
 
virtual void on_parent_fore_color_changed (const event_args &e)
 
virtual void on_resize (const event_args &e)
 
virtual void on_size_changed (const event_args &e)
 
virtual void on_text_changed (const event_args &e)
 
virtual void on_visible_changed (const event_args &e)
 
virtual void recreate_handle ()
 
virtual void set_bounds_core (int32_t x, int32_t y, int32_t width, int32_t height, bounds_specified specified)
 Performs the work of setting the specified bounds of this control. More...
 
virtual void set_client_size_core (int32_t width, int32_t height)
 Sets the size of the client area of the control. More...
 
void set_style (control_styles flag, bool value)
 Sets a specified control_styles flag to either true or false. More...
 
- Protected Member Functions inherited from xtd::forms::component
bool design_mode () const
 Gets a value that indicates whether the component is currently in design mode. More...
 

Additional Inherited Members

- Public Types inherited from xtd::forms::control
using control_collection = layout::arranged_element_collection< control_ref >
 Represents a collection of controls. More...
 
- Static Public Member Functions inherited from xtd::forms::control
template<typename control_t >
static std::unique_ptr< control_t > create (const drawing::point &location={-1, -1}, const drawing::size &size={-1, -1}, const drawing::color &back_color=drawing::color::empty, const drawing::color &fore_color=drawing::color::empty)
 
template<typename control_t >
static std::unique_ptr< control_t > create (const control &parent, const drawing::point &location={-1, -1}, const drawing::size &size={-1, -1}, const drawing::color &back_color=drawing::color::empty, const drawing::color &fore_color=drawing::color::empty)
 
template<typename control_t >
static std::unique_ptr< control_t > create (const ustring &text, const drawing::point &location={-1, -1}, const drawing::size &size={-1, -1}, const drawing::color &back_color=drawing::color::empty, const drawing::color &fore_color=drawing::color::empty)
 
template<typename control_t >
static std::unique_ptr< control_t > create (const control &parent, const ustring &text, const drawing::point &location={-1, -1}, const drawing::size &size={-1, -1}, const drawing::color &back_color=drawing::color::empty, const drawing::color &fore_color=drawing::color::empty)
 
static std::optional< control_reffrom_child_handle (intptr_t handle)
 
static std::optional< control_reffrom_handle (intptr_t handle)
 
static forms::mouse_buttons mouse_buttons ()
 
- Public Attributes inherited from xtd::forms::control
event< control, event_handler< control & > > auto_size_changed
 
event< control, event_handler< control & > > back_color_changed
 
event< control, event_handler< control & > > click
 
event< control, event_handler< control & > > client_size_changed
 
event< control, control_event_handler< control & > > control_added
 
event< control, control_event_handler< control & > > control_removed
 
event< control, event_handler< control & > > cursor_changed
 
event< control, event_handler< control & > > dock_changed
 
event< control, event_handler< control & > > double_click
 
event< control, event_handler< control & > > enabled_changed
 
event< control, event_handler< control & > > font_changed
 
event< control, event_handler< control & > > fore_color_changed
 
event< control, event_handler< control & > > got_focus
 
event< control, event_handler< control & > > handle_created
 
event< control, event_handler< control & > > handle_destroyed
 
event< control, key_event_handler< control & > > key_down
 
event< control, key_press_event_handler< control & > > key_press
 
event< control, key_event_handler< control & > > key_up
 
event< control, event_handler< control & > > layout
 Occurs when a control should reposition its child controls. More...
 
event< control, event_handler< control & > > location_changed
 
event< control, event_handler< control & > > lost_focus
 
event< control, mouse_event_handler< control & > > mouse_click
 
event< control, mouse_event_handler< control & > > mouse_double_click
 
event< control, mouse_event_handler< control & > > mouse_down
 
event< control, event_handler< control & > > mouse_enter
 
event< control, mouse_event_handler< control & > > mouse_horizontal_wheel
 
event< control, event_handler< control & > > mouse_leave
 
event< control, mouse_event_handler< control & > > mouse_move
 
event< control, mouse_event_handler< control & > > mouse_up
 
event< control, mouse_event_handler< control & > > mouse_wheel
 
event< control, paint_event_handler< control & > > paint
 
event< control, event_handler< control & > > parent_changed
 
event< control, event_handler< control & > > resize
 
event< control, event_handler< control & > > size_changed
 
event< control, event_handler< control & > > text_changed
 
event< control, event_handler< control & > > visible_changed
 

Detailed Description

Represents a Windows button control.

Remarks
A Button can be clicked by using the mouse, ENTER key, or SPACEBAR if the button has focus.
Set the accept_button or cancel_button property of a form to allow users to click a button by pressing the ENTER or ESC keys even if the button does not have focus. This gives the form the behavior of a dialog box.
When you display a form using the show_dialog method, you can use the dialog_result property of a button to specify the return value of show_dialog.
You can change the button's appearance. For example, to make it appear flat for a Web look, set the flat_style property to flat_style::flat. The flat_style property can also be set to flat_style::popup, which appears flat until the mouse pointer passes over the button; then the button takes on the standard Windows button appearance.
Note
If the control that has focus accepts and processes the ENTER key press, the button does not process it. For example, if a multiline text_box or another button has focus, that control processes the ENTER key press instead of the accept button.
Example
The following code example demonstrate the use of button control.
#include <xtd/xtd.forms>
using namespace xtd;
using namespace xtd::forms;
namespace examples {
class form1 : public form {
public:
form1() {
text("Button example");
button1.parent(*this);
button1.text("Button 1");
button1.location({50, 50});
button1.click += [this](control& sender, const event_args& e) {
label1.text(strings::format("Button 1 clicked {} times", ++button1_clicked));
};
button2.parent(*this);
button2.text("Button 2");
button2.location({50, 100});
button2.size({200, 75});
button2.click += [this](control& sender, const event_args& e) {
label2.text(strings::format("Button 2 clicked {} times", ++button2_clicked));
};
label1.parent(*this);
label1.text("Button 1 clicked 0 times");
label1.location({50, 200});
label1.width(200);
label2.parent(*this);
label2.text("Button 2 clicked 0 times");
label2.location({50, 230});
label2.width(200);
}
private:
label label1;
label label2;
int button1_clicked = 0;
int button2_clicked = 0;
};
}
int main() {
application::run(examples::form1());
}

Constructor & Destructor Documentation

§ button()

xtd::forms::button::button ( )
default

Initializes a new instance of the Button class.

Remarks
By default the button displays no caption. To specify the caption text, set the text property.

Member Function Documentation

§ auto_size_mode() [1/2]

virtual forms::auto_size_mode xtd::forms::button::auto_size_mode ( ) const
inlinevirtual

Gets the mode by which the button automatically resizes itself.

Returns
One of the AutoSizeMode values. The default value is grow_only.

§ auto_size_mode() [2/2]

virtual button& xtd::forms::button::auto_size_mode ( forms::auto_size_mode  value)
virtual

Sets the mode by which the button automatically resizes itself.

Parameters
valueOne of the AutoSizeMode values. The default value is growonly.

§ create_params()

forms::create_params xtd::forms::button::create_params ( ) const
overrideprotectedvirtual

Gets a create_params on the base class when creating a window.

Returns
A create_params object on the base class when creating a window.
Remarks
Inheriting classes can override this property to add extra functionality, but must first call the create_params constructor on the base class to verify that the control continues to work correctly.

Reimplemented from xtd::forms::control.

§ dialog_result() [1/2]

forms::dialog_result xtd::forms::button::dialog_result ( ) const
inlineoverridevirtual

Gets the value returned to the parent form when the button is clicked.

Returns
One of the DialogResult values.
Remarks
When a form is shown as a dialog box using the show_dialog method and one of its buttons is clicked, the button's dialog_result value is assigned to the form's dialog_result property.

Implements xtd::forms::ibutton_control.

§ dialog_result() [2/2]

control& xtd::forms::button::dialog_result ( forms::dialog_result  dialog_result)
overridevirtual

Sets the value returned to the parent form when the button is clicked.

Parameters
dialog_resultOne of the DialogResult values.
Remarks
When a form is shown as a dialog box using the show_dialog method and one of its buttons is clicked, the button's dialog_result value is assigned to the form's dialog_result property.

Implements xtd::forms::ibutton_control.

§ measure_control()

drawing::size xtd::forms::button::measure_control ( ) const
overridevirtual

Measure this control.

Returns
The drawing::size size of this control.
Remarks
This method is used when auto_size is true.

Reimplemented from xtd::forms::control.

§ notify_default()

void xtd::forms::button::notify_default ( bool  value)
overridevirtual

Notifies a control that it is the default button so that its appearance and behavior is adjusted accordingly.

Parameters
valuetrue if the control should behave as a default button; otherwise false.
Remarks
This method is called by a parent form to make a control the default button. Default buttons are set to have an extra thick border.

Implements xtd::forms::ibutton_control.

§ on_click()

void xtd::forms::button::on_click ( const event_args e)
overrideprotectedvirtual

Raises the Click event.

Parameters
eAn event_args that contains the event data.

Reimplemented from xtd::forms::control.

§ perform_click()

void xtd::forms::button::perform_click ( )
overridevirtual

Generates a click event for the control.

Remarks
This method is called for the button that has focus, or for the default button (if no other button has focus) when the user presses the ENTER key. This method is also called when the user presses the ESC key if the button is set as the cancel button.

Implements xtd::forms::ibutton_control.

§ wnd_proc()

void xtd::forms::button::wnd_proc ( message message)
overrideprotectedvirtual

Processes Windows messages.

Parameters
mThe Windows Message to process.
Remarks
All messages are sent to the wnd°proc method after getting filtered through the pre_process_message method.

Reimplemented from xtd::forms::control.


The documentation for this class was generated from the following file: