demonstrates some events received by form.
#include <xtd/threading/thread_pool>
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/list_box>
#include <xtd/startup>
class something_ready_notifier :
public object {
public:
something_ready_notifier() = default;
void on_something_ready() {
something_ready.invoke(*this, event_args::empty);
}
void notify_something_ready() {
synchronizer.begin_invoke({*this, &something_ready_notifier::on_something_ready});
}
protected:
};
class form1 :
public form {
public:
static void main() {
application::run(form1 {});
}
form1() {
text(
"Send messages to form");
client_size({300, 300});
controls().push_back_range({button_send, list_box_messages});
notifier.something_ready += [&] {
static auto counter = 0;
list_box_messages.items().push_back(string::format("Something ready notified {} times", ++counter));
list_box_messages.selected_index(list_box_messages.items().size() - 1);
};
button_send.auto_size(true);
button_send.location({10, 10});
button_send.text("Send async notify something ready");
button_send.click += [&] {
thread_pool::queue_user_work_item([&] {
thread::sleep(2_s);
notifier.notify_something_ready();
});
};
list_box_messages.location({10, 50});
list_box_messages.size({280, 240});
}
protected:
something_ready_notifier notifier;
};
Represents an event.
Definition event.hpp:21
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
#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::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:11
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10