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

shows how to use xtd::forms::control::name property and xtd::forms::layout::arranged_element_collection::operator[] name operator.

Windows

macOS

Gnome

#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/label>
using namespace xtd;
using namespace xtd::forms;
namespace control_with_name_operator_example {
class main_form : public form {
public:
main_form() {
controls().push_back_range({button1, label1});
button1.name("button1");
label1.name("label1");
controls()["button1"].value().get().location({10, 10});
controls()["button1"].value().get().text("Click me");
as<button>(controls()["button1"].value().get()).auto_repeat(true);
controls()["button1"].value().get().click += [&] {
static int count = 0;
controls()["label1"].value().get().text(string::format("button clicked {} times", ++count));
};
controls()["label1"].value().get().auto_size(true);
controls()["label1"].value().get().location({10, 50});
controls()["label1"].value().get().text("button clicked 0 times");
}
private:
button button1;
label label1;
};
}
auto main() -> int {
xtd::forms::application::run(control_with_name_operator_example::main_form {});
}
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
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
Represents a standard Windows label.
Definition label.hpp:38
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.hpp:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10