xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
main_menu.cpp

The following code example demonstrate the use of main_menu control.

Windows

macOS

Gnome

#include <xtd/xtd>
using namespace xtd;
using namespace xtd::forms;
namespace examples {
class form1 : public form {
public:
form1() {
text("Main menu example");
menu({
{system_texts::new_(), {*this, &form1::on_menu_click}, menu_images::file_new(), shortcut::cmd_n},
{"-"},
{system_texts::open(), {*this, &form1::on_menu_click}, menu_images::file_open(), shortcut::cmd_o},
{"Open recen", {
{"Path/File1", {*this, &form1::on_menu_click}},
{"Path/File2", {*this, &form1::on_menu_click}},
{"Path/File3", {*this, &form1::on_menu_click}},
{"Path/File4", {*this, &form1::on_menu_click}},
{"Path/File5", {*this, &form1::on_menu_click}},
}},
{system_texts::close(), {*this, &form1::on_menu_click}, shortcut::cmd_w},
{"-"},
{system_texts::save(), {*this, &form1::on_menu_click}, menu_images::file_save(), shortcut::cmd_s},
{system_texts::save_as(), {*this, &form1::on_menu_click}},
{"-"},
{"Page &Seup...", {*this, &form1::on_menu_click}},
{system_texts::print(), {*this, &form1::on_menu_click}, menu_images::file_print(), shortcut::cmd_p},
{system_texts::print_preview(), {*this, &form1::on_menu_click}, menu_images::file_print_preview()},
{"-"},
}},
{system_texts::undo(), {*this, &form1::on_menu_click}, menu_images::edit_undo(), shortcut::cmd_z},
{system_texts::redo(), {*this, &form1::on_menu_click}, menu_images::edit_redo(), shortcut::cmd_shift_z},
{"-"},
{system_texts::cut(), {*this, &form1::on_menu_click}, menu_images::edit_cut(), shortcut::cmd_x},
{system_texts::copy(), {*this, &form1::on_menu_click}, menu_images::edit_copy(), shortcut::cmd_c},
{system_texts::paste(), {*this, &form1::on_menu_click}, menu_images::edit_paste(), shortcut::cmd_v},
{"-"},
{system_texts::select_all(), {*this, &form1::on_menu_click}, shortcut::cmd_a},
{"-"},
{system_texts::options(), {*this, &form1::on_menu_click}},
}},
{system_texts::back(), {*this, &form1::on_menu_click}, menu_images::view_back()},
{system_texts::forward(), {*this, &form1::on_menu_click}, menu_images::view_forward()},
{"-"},
{"Show", {*this, &form1::on_menu_click}},
{"Hide", {*this, &form1::on_menu_click}},
}},
{"Value A", {*this, &form1::on_menu_click}, menu_item_kind::check, true, shortcut::alt_1},
{"Value B", {*this, &form1::on_menu_click}, menu_item_kind::check, shortcut::alt_2},
{"Value C", {*this, &form1::on_menu_click}, menu_item_kind::check, true, shortcut::alt_3},
{"-"},
{"Value D", {*this, &form1::on_menu_click}, menu_item_kind::radio, static_cast<shortcut>(keys::alt|keys::d)},
{"Value E", {*this, &form1::on_menu_click}, menu_item_kind::radio, true, static_cast<shortcut>(keys::alt|keys::e)},
{"Value F", {*this, &form1::on_menu_click}, menu_item_kind::radio, static_cast<shortcut>(keys::alt|keys::f)},
{"-"},
{"Value G", {*this, &form1::on_menu_click}, menu_item_kind::radio, static_cast<shortcut>(keys::alt|keys::shift|keys::left)},
{"Value H", {*this, &form1::on_menu_click}, menu_item_kind::radio},
{"Value I", {*this, &form1::on_menu_click}, menu_item_kind::radio, true},
}},
{system_texts::about(), {*this, &form1::on_menu_click}},
}},
});
list_box1.parent(*this);
list_box1.dock(dock_style::fill);
}
void on_menu_click(object& sender, const event_args& e) {
list_box1.items().push_back(ustring::format("{} clicked", as<menu_item&>(sender).text()));
list_box1.selected_index(list_box1.items().size() - 1);
}
private:
list_box list_box1;
};
}
int main() {
application::run(examples::form1());
}
static void exit()
Informs all message pumps that they must terminate, and then closes all application windows after the...
static void enable_menu_images()
Enables menu images for the application.
static void run()
Begins running a standard application message loop on the current thread, without a form.
static xtd::drawing::image edit_copy()
Edit copy image object.
Definition: menu_images.h:221
static xtd::drawing::image file_print()
File print image object.
Definition: menu_images.h:89
static xtd::drawing::image file_print_preview()
File print preview image object.
Definition: menu_images.h:111
static xtd::drawing::image file_save()
File save image object.
Definition: menu_images.h:67
static xtd::drawing::image file_exit()
File exit image object.
Definition: menu_images.h:133
static xtd::drawing::image file_new()
File new image object.
Definition: menu_images.h:23
static xtd::drawing::image file_open()
File open image object.
Definition: menu_images.h:45
static xtd::drawing::image edit_cut()
Edit cut image object.
Definition: menu_images.h:199
static xtd::drawing::image edit_redo()
Edit undo image object.
Definition: menu_images.h:177
static xtd::drawing::image edit_paste()
Edit paste image object.
Definition: menu_images.h:243
static xtd::drawing::image view_forward()
View forward image object.
Definition: menu_images.h:287
static xtd::drawing::image view_back()
View back image object.
Definition: menu_images.h:265
static xtd::drawing::image edit_undo()
Edit undo image object.
Definition: menu_images.h:155
static xtd::ustring file()
Gets a system-defined text that has a string value of "&File". This field is constant.
static xtd::ustring options()
Gets a system-defined text that has a string value of "&Options". This field is constant.
static xtd::ustring print_preview()
Gets a system-defined text that has a string value of "Print Re&view". This field is constant.
static xtd::ustring undo()
Gets a system-defined text that has a string value of "&Undo". This field is constant.
static xtd::ustring help()
Gets a system-defined text that has a string value of "&Help". This field is constant.
static xtd::ustring select_all()
Gets a system-defined text that has a string value of "Select &All". This field is constant.
static xtd::ustring save()
Gets a system-defined text that has a string value of "&Save". This field is constant.
static xtd::ustring new_()
Gets a system-defined text that has a string value of "&New". This field is constant.
static xtd::ustring forward()
Gets a system-defined text that has a string value of "&Forward". This field is constant.
static xtd::ustring back()
Gets a system-defined text that has a string value of "&Back". This field is constant.
static xtd::ustring paste()
Gets a system-defined text that has a string value of "&Paste". This field is constant.
static xtd::ustring save_as()
Gets a system-defined text that has a string value of "Save &As...". This field is constant.
static xtd::ustring print()
Gets a system-defined text that has a string value of "&Print...". This field is constant.
static xtd::ustring view()
Gets a system-defined text that has a string value of "&View". This field is constant.
static xtd::ustring copy()
Gets a system-defined text that has a string value of "&Copy". This field is constant.
static xtd::ustring edit()
Gets a system-defined text that has a string value of "&Edit". This field is constant.
static xtd::ustring redo()
Gets a system-defined text that has a string value of "&Redo". This field is constant.
static xtd::ustring open()
Gets a system-defined text that has a string value of "&Open...". This field is constant.
static xtd::ustring exit()
Gets a system-defined text that has a string value of "E&xit". This field is constant.
static xtd::ustring about()
Gets a system-defined text that has a string value of "&About". This field is constant.
static xtd::ustring cut()
Gets a system-defined text that has a string value of "Cu&t". This field is constant.
static xtd::ustring close()
Gets a system-defined text that has a string value of "&Close". This field is constant.
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:689
@ e
The E key.
@ menu
The system-defined color of a menu's background.
shortcut
Specifies shortcut keys that can be used by menu items.
Definition: shortcut.h:19
@ alt_f4
The shortcut keys ALT+F4.
@ cmd_p
The shortcut keys CMD+P.
@ alt_2
The shortcut keys ALT+2.
@ cmd_shift_z
The shortcut keys CMD+SHIFT+Z.
@ cmd_a
The shortcut keys CMD+A.
@ cmd_s
The shortcut keys CMD+S.
@ cmd_v
The shortcut keys CMD+V.
@ cmd_x
The shortcut keys CMD+X.
@ cmd_z
The shortcut keys CMD+Z.
@ cmd_o
The shortcut keys CMD+O.
@ cmd_n
The shortcut keys CMD+N.
@ cmd_w
The shortcut keys CMD+W.
@ cmd_c
The shortcut keys CMD+C.
@ alt_1
The shortcut keys ALT+1.
@ alt_3
The shortcut keys ALT+3.
@ shift
The SHIFt modifier key.
@ alt
The ALT modifier key.
@ left
The LEFT key.
@ d
The D key.
@ f
The F key.
@ e
The E key.
@ check
Check menu item.
@ radio
Radio menu item.
@ fill
All the control's edges are docked to the all edges of its containing control and sized appropriately...
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17