xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
timer.cpp

The following code example demonstrate the use of timer component.

Windows

macOS

Gnome

#include <xtd/xtd>
using namespace std::literals;
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::forms;
namespace examples {
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(100ms);
timer1.tick += [&](object& sender, const event_args& e) {
label1.text(ustring::format("{:F1}", ++counter / 10.0));
};
text("Timer example");
client_size({230, 130});
}
private:
timer timer1;
label label1;
button button1;
int counter = 0;
};
}
int main() {
application::run(examples::form1());
}
Defines a particular format for text, including font face, size, and style attributes....
Definition: font.h:39
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
Represents a Windows button control.
Definition: button.h:54
virtual const xtd::ustring & text() const
Gets the text associated with this control.
Definition: control.h:650
Represents a window or dialog box that makes up an application's user interface.
Definition: form.h:40
control & parent(const control &value) override
Sets the parent container of the control.
Represents a standard Windows label.
Definition: label.h:26
Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in...
Definition: timer.h:29
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition: bitmap.h:11
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17