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

demonstrates the use of xtd::forms::lcd_label control.

Windows

macOS

Gnome

#include <xtd/drawing/color_converter>
#include <xtd/forms/application>
#include <xtd/forms/form>
#include <xtd/forms/lcd_label>
#include <xtd/forms/timer>
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::forms;
auto main() -> int {
auto show_seconds = true;
auto clock_timer = timer {};
clock_timer.interval(100_ms);
clock_timer.enabled(true);
auto form_main = form {};
form_main.text("Clock");
form_main.start_position(form_start_position::center_screen);
form_main.auto_size_mode(forms::auto_size_mode::grow_and_shrink);
form_main.auto_size(true);
auto label = lcd_label {};
label.parent(form_main);
label.height(403);
label.digit_spacing(4);
label.fore_color(color::lime);
label.back_color(color_converter::average(color::black, label.fore_color(), 0.20));
label.segment_style(segment_style::modern);
label.show_back_digit(false);
label.text(date_time::now().to_long_time_string());
clock_timer.tick += [&] {
auto now = date_time::now();
label.text(show_seconds ? now.to_long_time_string() : now.to_short_time_string().replace(':', now.second() % 2 ? ' ' : ':'));
form_main.center_to_screen();
};
label.click += [&] {show_seconds = !show_seconds;};
application::run(form_main);
}
virtual drawing::color fore_color() const noexcept
Gets the foreground color of the control.
virtual int32 height() const noexcept
Gets the height of the control.
event< control, event_handler > click
Occurs when the xtd::forms::control is clicked.
Definition control.h:1485
virtual drawing::color back_color() const noexcept
Gets the background color for the control.
virtual const xtd::string & text() const noexcept
Gets the text associated with this control.
virtual bool auto_size() const noexcept
Gets a value that indicates whether the control resizes based on its contents.
virtual std::optional< control_ref > parent() const noexcept
Gets the parent container of the control.
Represents a window or dialog box that makes up an application's user interface.
Definition form.h:54
Represents a standard Windows label.
Definition label.h:38
Represents a lcd label.
Definition lcd_label.h:40
Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in...
Definition timer.h:38
virtual time_span interval() const noexcept
Gets the time, in milliseconds, before the tick event is raised relative to the last occurrence of th...
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.h:11
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.h:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10