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

demonstrates some events received by form.

Windows

macOS

Gnome

#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>
using namespace xtd;
using namespace xtd::forms;
using namespace xtd::threading;
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:
form synchronizer;
};
class form1 : public form {
public:
static void main() {
application::run(form1 {});
}
form1() {
text("Send messages to form");
location({100, 100});
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(ustring::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:
button button_send;
list_box list_box_messages;
something_ready_notifier notifier;
};
startup_(form1::main);
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
Represents a standard Windows list box.
Definition list_box.h:31
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:32
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:166
@ location
Specifies that both the x and y coordinates of the control are defined.
@ text
The xtd::forms::status_bar_panel displays text in the standard font.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.h:12
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.h:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10