xtd 0.2.0
Loading...
Searching...
No Matches
xtd::forms::tool_bar_button Class Reference
Inheritance diagram for xtd::forms::tool_bar_button:
xtd::forms::component xtd::iclonable xtd::iequatable< tool_bar_button > xtd::object xtd::interface xtd::interface xtd::equality_operators< type_t, equatable_t >

Definition

Represents a toolbar button.

Header
#include <xtd/forms/tool_bar_button>
Namespace
xtd::forms
Library
xtd.forms
Examples
The following code example demonstrates the use of xtd::forms::tool_bar_button control.
#include <xtd/drawing/texts>
#include <xtd/forms/application>
#include <xtd/forms/choice>
#include <xtd/forms/form>
#include <xtd/forms/list_box>
#include <xtd/forms/progress_bar>
#include <xtd/forms/timer>
#include <xtd/forms/tool_bar>
#include <xtd/forms/tool_bar_images>
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::forms;
namespace tool_bar_example {
class form1 : public form {
public:
form1() {
text("Toolbar example");
client_size({820, 500});
controls().push_back_range({list_box1, tool_bar2, tool_bar1});
tool_bar(tool_bar1);
active_control(list_box1);
list_box1.dock(dock_style::fill);
choice1.items().push_back_range({"Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8", "Item9", "Item10"});
choice1.selected_index(0);
choice1.selected_value_changed += [&] {
list_box1.items().push_back(string::format("{} selected", choice1.selected_item()));
list_box1.selected_index(list_box1.items().size() - 1);
};
progress_bar1.width(150);
progress_timer1.interval_milliseconds(50);
progress_timer1.start();
progress_timer1.tick += [&] {
progress_bar1.value(progress_bar1.value() < progress_bar1.maximum() ? progress_bar1.value() + 1 : progress_bar1.minimum());
};
tool_bar1.image_list().images().push_back_range({tool_bar_images::file_new(), tool_bar_images::file_open(), tool_bar_images::file_save(), tool_bar_images::file_print(), tool_bar_images::edit_cut(), tool_bar_images::edit_copy(), tool_bar_images::edit_paste(), tool_bar_images::help()});
tool_bar1.buttons().push_back_range({new_tool_bar_button, open_tool_bar_button, save_tool_bar_button, print_tool_bar_button, tool_bar1_separator1, cut_tool_bar_button, copy_tool_bar_button, paste_tool_bar_button, tool_bar1_separator2, choice_tool_bar_button, tool_bar1_separator3, help_tool_bar_button});
tool_bar1.button_click += {*this, &form1::on_tool_bar_button_click};
tool_bar2.dock(dock_style::bottom);
tool_bar2.show_text(true);
tool_bar2.image_list().image_size({24, 24});
tool_bar2.image_list().images().push_back_range({tool_bar_images::from_name("media-playback-start"), tool_bar_images::from_name("media-skip-backward"), tool_bar_images::from_name("media-playback-stop"), tool_bar_images::from_name("media-skip-forward"), tool_bar_images::from_name("media-record"), tool_bar_images::from_name("media-eject")});
tool_bar2.buttons().push_back_range({play_tool_bar_button, tool_bar2_separator1, skip_backward_tool_bar_button, stop_tool_bar_button, skip_forward_tool_bar_button, tool_bar2_separator2, record_tool_bar_button, tool_bar2_separator3, progress_tool_bar_button, tool_bar2_separator4, eject_tool_bar_button});
tool_bar2.button_click += {*this, &form1::on_tool_bar_button_click};
record_tool_bar_button.enabled(false);
}
private:
void on_tool_bar_button_click(object& sender, const tool_bar_button_click_event_args& e) {
if (e.button().style() == tool_bar_button_style::toggle_button)
list_box1.items().push_back(string::format("Button {} clicked, pushed = {}", e.button().text(), e.button().pushed()));
else
list_box1.items().push_back(string::format("Button {} clicked", e.button().text()));
list_box1.selected_index(list_box1.items().size() - 1);
}
void on_menu_click(object& sender, const event_args& e) {
list_box1.items().push_back(string::format("Menu item {} clicked", as<menu_item>(sender).text()));
list_box1.selected_index(list_box1.items().size() - 1);
}
list_box list_box1;
menu_item context_help_context_menu_item {"Help context", {*this, &form1::on_menu_click}};
menu_item context_help_index_menu_item {"Help index", {*this, &form1::on_menu_click}};
menu_item context_help_search_menu_item {"Help search", {*this, &form1::on_menu_click}};
menu_item context_separator_menu_item {"-"};
menu_item context_about_menu_item {texts::about(), {*this, &form1::on_menu_click}};
forms::context_menu context_menu1 {context_help_context_menu_item, context_help_index_menu_item, context_help_search_menu_item, context_separator_menu_item, context_about_menu_item};
forms::tool_bar tool_bar1;
choice choice1;
tool_bar_button new_tool_bar_button = tool_bar_button::create_push_button(texts::new_(), 0);
tool_bar_button open_tool_bar_button = tool_bar_button::create_push_button(texts::open(), 1);
tool_bar_button save_tool_bar_button = tool_bar_button::create_push_button(texts::save(), 2);
tool_bar_button print_tool_bar_button = tool_bar_button::create_push_button(texts::print(), 3);
tool_bar_button tool_bar1_separator1 = tool_bar_button::create_separator();
tool_bar_button cut_tool_bar_button = tool_bar_button::create_push_button(texts::cut(), 4);
tool_bar_button copy_tool_bar_button = tool_bar_button::create_push_button(texts::copy(), 5);
tool_bar_button paste_tool_bar_button = tool_bar_button::create_push_button(texts::paste(), 6);
tool_bar_button tool_bar1_separator2 = tool_bar_button::create_separator();
tool_bar_button choice_tool_bar_button = tool_bar_button::create_control("Items", choice1);
tool_bar_button tool_bar1_separator3 = tool_bar_button::create_stretchable_separator();
tool_bar_button help_tool_bar_button = tool_bar_button::create_drop_down_button(texts::help(), 7, context_menu1);
forms::tool_bar tool_bar2;
progress_bar progress_bar1;
timer progress_timer1;
tool_bar_button play_tool_bar_button = tool_bar_button::create_push_button("&Play", 0);
tool_bar_button tool_bar2_separator1 = tool_bar_button::create_separator();
tool_bar_button skip_backward_tool_bar_button = tool_bar_button::create_push_button("Skip &Backward", 1);
tool_bar_button stop_tool_bar_button = tool_bar_button::create_push_button("S&top", 2);
tool_bar_button skip_forward_tool_bar_button = tool_bar_button::create_push_button("Skip &Forward", 3);
tool_bar_button tool_bar2_separator2 = tool_bar_button::create_separator();
tool_bar_button record_tool_bar_button = tool_bar_button::create_push_button("&Record", 4);
tool_bar_button tool_bar2_separator3 = tool_bar_button::create_separator();
tool_bar_button progress_tool_bar_button = tool_bar_button::create_control(progress_bar1);
tool_bar_button tool_bar2_separator4 = tool_bar_button::create_stretchable_separator();
tool_bar_button eject_tool_bar_button = tool_bar_button::create_toggle_button("&Eject", 5);
};
}
auto main() -> int {
application::run(tool_bar_example::form1 {});
}
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.h:18
static void run()
Begins running a standard application message loop on the current thread, without a form.
Represents a choice control.
Definition choice.h:37
Represents a shortcut menu.
Definition context_menu.h:36
Represents a window or dialog box that makes up an application's user interface.
Definition form.h:54
Represents a standard Windows list box.
Definition list_box.h:33
Represents an individual item that is displayed within a main_menu or context_menu.
Definition menu_item.h:31
Represents a Windows progress bar control.
Definition progress_bar.h:40
Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in...
Definition timer.h:38
Provides data for the xtd::forms::tool_bar::button_click event.
Definition tool_bar_button_click_event_args.h:25
Represents a toolbar button.
Definition tool_bar_button.h:43
Represents a Windows toolbar.
Definition tool_bar.h:52
@ e
The E key.
@ right
The text is aligned to the right of the toolbar button image.
@ text
The xtd::forms::status_bar_panel displays text in the standard font.
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.h:11
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.h:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Remarks
xtd::forms::tool_bar_button controls are parented by xtd::forms::tool_bar controls. Common properties to set once the toolbar button has been created are xtd::forms::tool_bar_button::text and xtd::forms::tool_bar_button::image_index. Set the xtd::forms::tool_bar_button::text property of the button to display text beneath or to the right of the image. To assign images to the buttons by creating an xtd::forms::image_list, assigning it to the xtd::forms::tool_bar::image_list property of the toolbar; then assign the image index value to the xtd::forms::tool_bar_button::image_index property of the button.
To change the appearance of the toolbar buttons assigned to the toolbar, set the xtd::forms::tool_bar::appearance property of the parent toolbar control. The xtd::forms::tool_bar_appearance::flat appearance gives the buttons a flat appearance. As the mouse pointer moves over the buttons, their appearance changes to three-dimensional. Button separators appear as lines rather than spaces between the buttons when the buttons have a flat appearance. If the xtd::forms::tool_bar::appearance property is set to xtd::forms::tool_bar_appearance::normal, the buttons appear raised and three-dimensional, and the separators appear as a gap between the buttons.
You can assign a xtd::forms::context_menu to a button if the xtd::forms::tool_bar_button::style property is set to xtd::forms::tool_bar_button_style::drop_down. When the button is clicked, the assigned menu is displayed.
To create a collection of xtd::forms::tool_bar_button controls to display on a xtd::forms::tool_bar, add the buttons individually by using the xtd::forms::tool_bar::tool_bar_button_collection::push_back method of the xtd::forms::tool_bar::buttons property. Alternatively, you can add several toolbar buttons using the xtd::forms::tool_bar::tool_bar_button_collection.push_back_range method.
Examples
application_enable_dark_mode.cpp, application_enable_light_mode.cpp, some_controls.cpp, some_system_controls.cpp, themes.cpp, and tool_bar.cpp.

Public Constructors

 tool_bar_button ()
 Initialises a new instance of xtd::forms::tool_bar_button class.
 
 tool_bar_button (const xtd::string &text)
 Initializes a new instance of the xtd::forms::tool_bar_button class and displays the assigned text on the button.
 

Public Properties

std::optional< xtd::forms::control_refcontrol () const noexcept
 Gets the control to be displayed in the control toolbar button.
 
tool_bar_buttoncontrol (const xtd::forms::control &value)
 Sets the control to be displayed in the control toolbar button.
 
tool_bar_buttoncontrol (std::nullptr_t value)
 Resets the control to be displayed in the control toolbar button.
 
std::optional< std::reference_wrapper< xtd::forms::context_menu > > drop_down_menu () const noexcept
 Gets the menu to be displayed in the drop-down toolbar button.
 
tool_bar_buttondrop_down_menu (const xtd::forms::context_menu &value)
 Sets the menu to be displayed in the drop-down toolbar button.
 
tool_bar_buttondrop_down_menu (std::nullptr_t value)
 Resets the menu to be displayed in the drop-down toolbar button.
 
bool enabled () const noexcept
 Gets a value indicating whether the button is enabled.
 
tool_bar_buttonenabled (bool value)
 Sets a value indicating whether the button is enabled.
 
size_t image_index () const noexcept
 Gets the index value of the image assigned to the button.
 
tool_bar_buttonimage_index (size_t value)
 Sets the index value of the image assigned to the button.
 
const xtd::stringname () const noexcept
 Gets the name of the button.
 
tool_bar_buttonname (const xtd::string &value)
 Sets the name of the button.
 
std::optional< std::reference_wrapper< xtd::forms::tool_bar > > parent () const noexcept
 Gets the toolbar control that the toolbar button is assigned to.
 
bool pushed () const noexcept
 Gets a value indicating whether a toggle-style toolbar button is currently in the pushed state.
 
tool_bar_buttonpushed (bool value)
 Sets a value indicating whether a toggle-style toolbar button is currently in the pushed state.
 
const xtd::drawing::rectanglerectangle () const noexcept
 Gets the bounding rectangle for a toolbar button.
 
xtd::forms::tool_bar_button_style style () const noexcept
 Gets the style of the toolbar button.
 
tool_bar_buttonstyle (xtd::forms::tool_bar_button_style value)
 Sets the style of the toolbar button.
 
std::any tag () const noexcept
 Gets the object that contains data about the toolbar button.
 
tool_bar_buttontag (std::any value)
 Sets the object that contains data about the toolbar button.
 
const xtd::stringtext () const noexcept
 Gets the text displayed on the toolbar button.
 
tool_bar_buttontext (const xtd::string &value)
 Sets the text displayed on the toolbar button.
 
const xtd::stringtool_tip_text () const noexcept
 Gets the text that appears as a xtd::forms::tool_tip for the button.
 
tool_bar_buttontool_tip_text (const xtd::string &value)
 Sets the text that appears as a xtd::forms::tool_tip for the button.
 
bool visible () const noexcept
 Gets a value indicating whether the toolbar button is visible.
 
tool_bar_buttonvisible (bool value)
 Sets a value indicating whether the toolbar button is visible.
 

Public Methods

bool equals (const tool_bar_button &other) const noexcept override
 
xtd::string to_string () const noexcept override
 Returns a string that represents the xtd::forms::tool_bar_button control.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 

Public Static Methods

static tool_bar_button create_control (const xtd::string &text, const xtd::forms::control &control)
 A factory to create a control toolbar button with specified text and control.
 
static tool_bar_button create_control (const xtd::forms::control &control)
 A factory to create a control toolbar button with specified control.
 
static tool_bar_button create_drop_down_button (const xtd::string &text, const xtd::forms::context_menu &drop_down_menu)
 A factory to create a drop-down toolbar button with specified text and context menu.
 
static tool_bar_button create_drop_down_button (size_t image_index, const xtd::forms::context_menu &drop_down_menu)
 A factory to create a drop-down toolbar button with specified image index and context menu.
 
static tool_bar_button create_drop_down_button (const xtd::string &text, size_t image_index, const xtd::forms::context_menu &drop_down_menu)
 A factory to create a drop-down toolbar button with specified text, image index and context menu.
 
static tool_bar_button create_push_button (const xtd::string &text)
 A factory to create a toolbar button with specified text.
 
static tool_bar_button create_push_button (size_t image_index)
 A factory to create a toolbar button with specified image index.
 
static tool_bar_button create_push_button (const xtd::string &text, size_t image_index)
 A factory to create a toolbar button with specified text and image index.
 
static tool_bar_button create_separator ()
 A factory to create a toolbar separator.
 
static tool_bar_button create_stretchable_separator ()
 A factory to create a toolbar stretchable separator.
 
static tool_bar_button create_toggle_button (const xtd::string &text)
 A factory to create a toolbar toggle button with specified text.
 
static tool_bar_button create_toggle_button (size_t image_index)
 A factory to create a toolbar toggle button with specified image index.
 
static tool_bar_button create_toggle_button (const xtd::string &text, size_t image_index)
 A factory to create a toolbar toggle button with specified text and image index.
 

Protected Methods

xtd::uptr< xtd::objectclone () const override
 Creates a new object that is a copy of the current instance.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Public Member Functions inherited from xtd::iclonable
- Public Member Functions inherited from xtd::iequatable< tool_bar_button >
virtual bool equals (const tool_bar_button &) const noexcept=0
 Indicates wheth er the current object is equal to another object of the same type.
 
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<typename object_a_t , typename object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 
- Protected Member Functions inherited from xtd::forms::component
 component ()
 Initialises a new instance of the component class.
 
virtual bool can_raise_events () const noexcept
 Gets a value indicating whether the component can raise an event.
 
bool design_mode () const noexcept
 Gets a value that indicates whether the component is currently in design mode.
 

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