#include <xtd/diagnostics/stopwatch>
#include <xtd/drawing/color_converter>
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/lcd_label>
#include <xtd/forms/panel>
#include "../properties/resources.hpp"
class main_form :
public form {
public:
main_form() {
client_size({275, 120});
icon(stopwatch_form::properties::resources::stopwatch_ico());
maximize_box(false);
watch_panel.parent(*this);
watch_panel.bounds({20, 10, 235, 50});
watch.parent(watch_panel);
watch.bounds({10, 8, 214, 33});
watch.text("00:00:00.000");
start_stop.parent(*this);
start_stop.location({10, 80});
start_stop.text("Start");
start_stop.click += event_handler(*this, &main_form::on_start_stop_click);
pause_resume.parent(*this);
pause_resume.location({100, 80});
pause_resume.text("Pause");
pause_resume.enabled(false);
pause_resume.click += event_handler(*this, &main_form::on_pause_resume_click);
reset.parent(*this);
reset.location({190, 80});
reset.text("Reset");
reset.enabled(false);
reset.click += event_handler(*this, &main_form::on_reset_click);
timer_chrono.interval(11_ms);
timer_chrono.tick += event_handler(*this, &main_form::on_timer_tick);
}
private:
void on_start_stop_click(
object& sender,
const event_args&
e) {
if (stopwatch.is_running()) stopwatch.stop();
else stopwatch.start();
timer_chrono.enabled(stopwatch.is_running());
start_stop.text(timer_chrono.enabled() ? "Stop" : "Start");
pause_resume.enabled(timer_chrono.enabled());
reset.enabled(!timer_chrono.enabled() || !stopwatch.is_running());
};
void on_pause_resume_click(
object& sender,
const event_args&
e) {
timer_chrono.enabled(!timer_chrono.enabled());
pause_resume.text(timer_chrono.enabled() ? "Pause" : "Resume");
start_stop.enabled(timer_chrono.enabled());
reset.enabled(!timer_chrono.enabled() || !stopwatch.is_running());
};
void on_reset_click(
object& sender,
const event_args&
e) {
timer_chrono.enabled(false);
stopwatch.reset();
start_stop.enabled(true);
pause_resume.enabled(false);
reset.enabled(false);
watch.text("00:00:00.000");
start_stop.text("Start");
pause_resume.text("Pause");
};
void on_timer_tick(
object& sender,
const event_args&
e) {
watch.text(string::format("{0:H}:{0:M}:{0:S}.{0:L}", stopwatch.elapsed()));
};
};
auto main() -> int {
}
Provides a set of methods and properties that you can use to accurately measure elapsed time.
Definition stopwatch.hpp:36
static xtd::drawing::color average(const xtd::drawing::color &color1, const xtd::drawing::color &color2, double weight) noexcept
Returns the weighted average color between the two given colors.
static const xtd::drawing::color lime
Gets a system-defined color that has an ARGB value of 0xFF00FF00. This field is constant.
Definition color.hpp:287
static const xtd::drawing::color black
Gets a system-defined color that has an ARGB value of 0xFF000000. This field is constant.
Definition color.hpp:80
Represents a Windows icon, which is a small bitmap image that is used to represent an object....
Definition icon.hpp:28
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.hpp:18
@ e
The E key.
Definition console_key.hpp:96
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.hpp:10
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