xtd 0.2.0
forms_timer.cpp

demonstrates the use of xtd::forms::timer component.

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::drawing;
using namespace xtd::forms;
namespace timer_example {
class form1 : public form {
public:
form1() {
label1.parent(*this);
label1.text("0.0");
label1.font(drawing::font("Arial", 48, font_style::italic));
label1.location({10, 10});
label1.auto_size(true);
label1.fore_color(color::dodger_blue);
button1.parent(*this);
button1.text("Start");
button1.location({10, 90});
button1.click += [&](object & sender, const event_args & e) {
timer1.enabled(!timer1.enabled());
button1.text(timer1.enabled() ? "Stop" : "Start");
};
timer1.interval(100_ms);
timer1.tick += [&](object & sender, const event_args & e) {
label1.text(string::format("{:F1}", ++counter / 10.0));
};
text("Timer example");
client_size({230, 130});
}
private:
timer timer1;
label label1;
int counter = 0;
};
}
auto main() -> int {
application::run(timer_example::form1 {});
}
static const xtd::drawing::color dodger_blue
Gets a system-defined color that has an ARGB value of 0xFF1E90FF. This field is constant.
Definition color.hpp:182
Defines a particular format for text, including font face, size, and style attributes....
Definition font.hpp:45
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.hpp:18
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
virtual const xtd::string & text() const noexcept
Gets the text associated with this control.
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
control & parent(const control &value) override
Sets the parent container of the control.
Represents a standard Windows label.
Definition label.hpp:38
Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in...
Definition timer.hpp:38
@ italic
Italic text.
Definition font_style.hpp:23
@ e
The E key.
Definition console_key.hpp:96
@ button1
The first button on the message box is the default button.
Definition message_dialog_default_button.hpp:24
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.hpp:10
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:217
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8