Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in Windows Forms applications and must be used in a window.
- Header
#include <xtd/forms/timer>
- Namespace
- xtd::forms
- Library
- xtd.forms
- Note
- xtd includes several timer classes, each of which offers different functionality:
- xtd::timers::timer, which fires an event and executes the code in one or more event sinks at regular intervals. The class is intended for use as a server-based or service component in a multithreaded environment; it has no user interface and is not visible at runtime.
- xtd::threading::timer, which executes a single callback method on a thread pool thread at regular intervals. The callback method is defined when the timer is instantiated and cannot be changed. Like the xtd::timers::timer class, this class is intended for use as a server-based or service component in a multithreaded environment; it has no user interface and is not visible at runtime.
- xtd::forms::timer, a Windows Forms component that fires an event and executes the code in one or more event sinks at regular intervals. The component has no user interface and is designed for use in a single-threaded environment; it executes on the UI thread.
- Examples
- The following code example demonstrates the use of timer component.
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/label>
namespace timer_example {
class form1 :
public form {
public:
form1() {
label1.location({10, 10});
label1.auto_size(true);
label1.fore_color(color::dodger_blue);
timer1.enabled(!timer1.enabled());
button1.text(timer1.enabled() ?
"Stop" :
"Start");
};
timer1.interval(100_ms);
timer1.tick += [&](
object & sender,
const event_args &
e) {
label1.text(ustring::format("{:F1}", ++counter / 10.0));
};
client_size({230, 130});
}
private:
timer timer1;
label label1;
int counter = 0;
};
}
auto main()->int {
}
- Examples:
- clock.cpp, dot_matrix_display.cpp, draw_point.cpp, forms_timer.cpp, fourteen_segment_display.cpp, lcd_label2.cpp, lcd_label_with_dot_matrix.cpp, lcd_label_with_fourteen_segment.cpp, lcd_label_with_nine_segment.cpp, lcd_label_with_seven_segment.cpp, lcd_label_with_sixteen_segment.cpp, nine_segment_display.cpp, progress_bar.cpp, seven_segment_display.cpp, sixteen_segment_display.cpp, status_bar.cpp, stopwatch_form.cpp, tool_bar.cpp, and wiggly.cpp.
|
| timer () |
| Initializes a new instance of the timer class. More...
|
|
|
virtual bool | enabled () const noexcept |
| Gets whether the timer is running. More...
|
|
virtual timer & | enabled (bool enabled) |
| Sets whether the timer is running. More...
|
|
virtual time_span | interval () const noexcept |
| Gets the time, in milliseconds, before the tick event is raised relative to the last occurrence of the tick event. More...
|
|
timer & | interval (const time_span &interval) |
| Sets the time, in milliseconds, before the tick event is raised relative to the last occurrence of the tick event. More...
|
|
virtual int32 | interval_milliseconds () const noexcept |
| Gets the time, in milliseconds, before the tick event is raised relative to the last occurrence of the tick event. More...
|
|
virtual timer & | interval_milliseconds (int32 interval) |
| Sets the time, in milliseconds, before the tick event is raised relative to the last occurrence of the tick event. More...
|
|
|
| object ()=default |
| Create a new instance of the ultimate base class object. More...
|
|
bool | equals (const object &obj) const noexcept |
| Determines whether the specified object is equal to the current object. More...
|
|
virtual size_t | get_hash_code () const noexcept |
| Serves as a hash function for a particular type. More...
|
|
virtual type_object | get_type () const noexcept |
| Gets the type of the current instance. More...
|
|
template<typename object_t > |
std::unique_ptr< object_t > | memberwise_clone () const noexcept |
| Creates a shallow copy of the current object. More...
|
|
virtual xtd::ustring | to_string () const noexcept |
| Returns a sxd::ustring that represents the current object. More...
|
|
static bool | equals (const object &object_a, const object &object_b) noexcept |
| Determines whether the specified object instances are considered equal. More...
|
|
static bool | reference_equals (const object &object_a, const object &object_b) noexcept |
| Determines whether the specified object instances are the same instance. More...
|
|
| component () |
| Initialises a new instance of the component class. More...
|
|
virtual bool | can_raise_events () const noexcept |
| Gets a value indicating whether the component can raise an event. More...
|
|
bool | design_mode () const noexcept |
| Gets a value that indicates whether the component is currently in design mode. More...
|
|
◆ timer()
xtd::forms::timer::timer |
( |
| ) |
|
Initializes a new instance of the timer class.
◆ enabled() [1/2]
virtual bool xtd::forms::timer::enabled |
( |
| ) |
const |
|
virtualnoexcept |
◆ enabled() [2/2]
virtual timer& xtd::forms::timer::enabled |
( |
bool |
enabled | ) |
|
|
virtual |
Sets whether the timer is running.
- Parameters
-
enabled | true if the timer is currently enabled; otherwise, false. The default is false. |
◆ interval() [1/2]
virtual time_span xtd::forms::timer::interval |
( |
| ) |
const |
|
virtualnoexcept |
◆ interval() [2/2]
Sets the time, in milliseconds, before the tick event is raised relative to the last occurrence of the tick event.
- Parameters
-
interval | An int32 specifying the number of milliseconds before the tick event is raised relative to the last occurrence of the tick event. The value cannot be less than one. |
◆ interval_milliseconds() [1/2]
virtual int32 xtd::forms::timer::interval_milliseconds |
( |
| ) |
const |
|
virtualnoexcept |
Gets the time, in milliseconds, before the tick event is raised relative to the last occurrence of the tick event.
- Returns
- An int32 specifying the number of milliseconds before the tick event is raised relative to the last occurrence of the tick event. The value cannot be less than one.
◆ interval_milliseconds() [2/2]
virtual timer& xtd::forms::timer::interval_milliseconds |
( |
int32 |
interval | ) |
|
|
virtual |
Sets the time, in milliseconds, before the tick event is raised relative to the last occurrence of the tick event.
- Parameters
-
interval | An int32 specifying the number of milliseconds before the tick event is raised relative to the last occurrence of the tick event. The value cannot be less than one. |
◆ on_tick()
virtual void xtd::forms::timer::on_tick |
( |
const event_args & |
e | ) |
|
|
protectedvirtual |
◆ start()
void xtd::forms::timer::start |
( |
| ) |
|
◆ stop()
void xtd::forms::timer::stop |
( |
| ) |
|
◆ tick
The documentation for this class was generated from the following file:
- xtd.forms/include/xtd/forms/timer.h