xtd 0.2.0
form_custom_event.cpp

demonstrates how to create custom event with form.

Windows

macOS

Gnome

#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/message_box>
using namespace xtd;
using namespace xtd::forms;
namespace custom_event_example {
class custom_event_args : public event_args {
public:
explicit custom_event_args(const std::any& tag) noexcept : tag_ {tag} {}
std::any tag() const noexcept {return tag_;}
private:
std::any tag_;
};
class form1 : public form {
public:
form1() {
text("Form custom event example");
button1.click += [&] {
static auto counter = 0;
custom_event.invoke(*this, custom_event_args {++counter});
};
custom_event += [&](object& sender, const custom_event_args& e) {
message_box::show(*this, string::format("Receive custom_event event ({})", any_cast<int>(e.tag())), "Custom event");
};
}
private:
button button1 = button::create(*this, "Send event", {10, 10}, {100, 25});
};
}
auto main() -> int {
application::run(custom_event_example::form1 {});
}
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.hpp:18
Represents an event.
Definition event.hpp:21
static void run()
Begins running a standard application message loop on the current thread, without a form.
Represents a Windows button control.
Definition button.hpp:49
static button create()
A factory to create an xtd::forms::button.
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
static dialog_result show(const iwin32_window &owner)
Displays a message box in front of the specified window.
xtd::delegate< void(xtd::object &sender, event_args_t e)> generic_event_handler
Represents the method that will handle an event when the event provides data.
Definition generic_event_handler.hpp:30
@ e
The E key.
Definition console_key.hpp:96
@ button1
The first button on the message box is the default button.
Definition message_dialog_default_button.hpp:24
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:217
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8