xtd 0.2.0
Loading...
Searching...
No Matches
form_show.cpp

This example demonstrates how to launch form as normal window , model-less window and modal window.

Windows

macOS

Gnome

#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/vertical_layout_panel>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::collections::generic;
using namespace xtd::forms;
namespace example {
class form1 : public form {
public:
form1() {
client_size({320, 610});
controls().push_back(layout_panel);
padding(5);
text("Form show example");
layout_panel.dock(dock_style::fill);
layout_panel.controls().push_back_range({button_normal, button_modeless, button_top_most, button_modal, button_sheet, button_sheet_modal});
layout_panel.control_layout_style(button_normal, {size_type::auto_size, true});
layout_panel.control_layout_style(button_modeless, {size_type::auto_size, true});
layout_panel.control_layout_style(button_top_most, {size_type::auto_size, true});
layout_panel.control_layout_style(button_modal, {size_type::auto_size, true});
layout_panel.control_layout_style(button_sheet, {size_type::auto_size, true});
layout_panel.control_layout_style(button_sheet_modal, {size_type::auto_size, true});
button_normal.text("Show normal");
button_normal.click += [&] {
auto dialog = new_ptr<form>();
dialog->text("dialog show normal");
dialog->size({250, 100});
dialog->show();
dialogs.push_back(dialog);
};
button_modeless.text("Show modeless");
button_modeless.click += [&] {
auto dialog = new_ptr<form>();
dialog->text("dialog show modeless");
dialog->size({250, 100});
dialog->owner(*this).show();
dialogs.push_back(dialog);
};
button_top_most.text("Show top most");
button_top_most.click += [&] {
auto dialog = new_ptr<form>();
dialog->text("dialog top most");
dialog->size({250, 100});
dialog->top_most(true).show();
dialogs.push_back(dialog);
};
button_modal.text("Show modal");
button_modal.click += [&] {
auto dialog = form::create("dialog show modal", drawing::size {250, 100});
dialog.show_dialog(*this);
};
button_sheet.text("Show sheet");
button_sheet.click += [&] {
auto dialog = new_ptr<form>();
dialog->form_border_style(form_border_style::fixed_3d);
dialog->text("dialog show sheet").size({250, 100});
dialog->key_up += [&](object & control, key_event_args & e) {
if (e.key_code() == keys::escape) as<form&>(control).close();
};
dialog->show_sheet(*this);
dialogs.push_back(dialog);
};
button_sheet_modal.text("Show sheet modal");
button_sheet_modal.click += [&] {
auto dialog = form::create("dialog show sheet modal", drawing::size {250, 100});
dialog.form_border_style(form_border_style::fixed_3d);
dialog.key_up += [&](object & control, key_event_args & e) {
if (e.key_code() == keys::escape) as<form&>(control).close();
};
dialog.show_sheet_dialog(*this);
};
}
static auto main() {
application::run(form1 {});
}
private:
vertical_layout_panel layout_panel;
button button_normal;
button button_modeless;
button button_top_most;
button button_modal;
button button_sheet;
button button_sheet_modal;
list<ptr<form>> dialogs;
};
}
startup_(example::form1::main);
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:71
Stores an ordered pair of integers, which specify a height and width.
Definition size.hpp:31
Represents a Windows button control.
Definition button.hpp:49
Defines the base class for controls, which are components with visual representation.
Definition control.hpp:81
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
Provides data for the xtd::forms::control::key_down or xtd::forms::control::key_up event.
Definition key_event_args.hpp:25
Represents a display device or multiple display devices on a single system.
Definition padding.hpp:25
Used to group collections of vertically aligned controls.
Definition vertical_layout_panel.hpp:31
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:175
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:15
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.hpp:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10