xtd 0.2.0
Loading...
Searching...
No Matches
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 std;
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, ustring::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.h:18
Represents an event.
Definition event.h:21
Represents a Windows button control.
Definition button.h:47
Represents a window or dialog box that makes up an application's user interface.
Definition form.h:52
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.h:22
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