demonstrates how to create custom event with form.
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/message_box>
namespace custom_event_example {
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
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 event_handler.hpp:22
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10