xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
date_time_picker.h
Go to the documentation of this file.
1 #pragma once
5 #include <chrono>
6 #include "control.h"
8 
10 namespace xtd {
12  namespace forms {
22  class forms_export_ date_time_picker : public control {
23  public:
26 
30  virtual date_time_picker_format format() const {return format_;}
35  virtual control& format(date_time_picker_format format);
36 
39  virtual std::chrono::system_clock::time_point max_date() const {return max_date_;}
43  virtual control& max_date(std::chrono::system_clock::time_point max_date);
47  virtual control& max_date(time_t max_date) {return this->max_date(std::chrono::system_clock::from_time_t(max_date));}
51  virtual control& max_date(const std::tm& max_date) {
52  std::tm internal_max_date = max_date;
53  return this->max_date(mktime(&internal_max_date));
54  }
58  virtual control& max_date(int32_t year, int32_t month, int32_t day) {
59  std::tm internal_max_date = {};
60  internal_max_date.tm_year = year - 1900;
61  internal_max_date.tm_mon = month - 1;
62  internal_max_date.tm_mday = day;
63  return max_date(mktime(&internal_max_date));
64  }
68  virtual control& max_date(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second) {
69  std::tm internal_max_date = {};
70  internal_max_date.tm_year = year - 1900;
71  internal_max_date.tm_mon = month - 1;
72  internal_max_date.tm_mday = day;
73  internal_max_date.tm_hour = hour;
74  internal_max_date.tm_min = minute;
75  internal_max_date.tm_sec = second;
76  return max_date(mktime(&internal_max_date));
77  }
78 
81  virtual std::chrono::system_clock::time_point min_date() const {return max_date_;}
85  virtual control& min_date(std::chrono::system_clock::time_point min_date);
89  virtual control& min_date(time_t min_date) {return this->min_date(std::chrono::system_clock::from_time_t(min_date));}
93  virtual control& min_date(const std::tm& min_date) {
94  std::tm internal_min_date = min_date;
95  return this->min_date(mktime(&internal_min_date));
96  }
100  virtual control& min_date(int32_t year, int32_t month, int32_t day) {
101  std::tm internal_min_date = {};
102  internal_min_date.tm_year = year - 1900;
103  internal_min_date.tm_mon = month - 1;
104  internal_min_date.tm_mday = day;
105  return min_date(mktime(&internal_min_date));
106  }
110  virtual control& min_date(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second) {
111  std::tm internal_min_date = {};
112  internal_min_date.tm_year = year - 1900;
113  internal_min_date.tm_mon = month - 1;
114  internal_min_date.tm_mday = day;
115  internal_min_date.tm_hour = hour;
116  internal_min_date.tm_min = minute;
117  internal_min_date.tm_sec = second;
118  return min_date(mktime(&internal_min_date));
119  }
120 
123  virtual std::chrono::system_clock::time_point value() const {return value_;}
126  virtual control& value(std::chrono::system_clock::time_point value);
129  virtual control& value(time_t value) {return this->value(std::chrono::system_clock::from_time_t(value));}
132  virtual control& value(const std::tm& value) {
133  std::tm internal_value = value;
134  return this->value(mktime(&internal_value));
135  }
138  virtual control& value(int32_t year, int32_t month, int32_t day) {
139  return value(year, month, day, 0, 0, 0);
140  }
143  virtual control& value(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second) {
144  std::tm internal_value = {};
145  internal_value.tm_year = year - 1900;
146  internal_value.tm_mon = month - 1;
147  internal_value.tm_mday = day;
148  internal_value.tm_hour = hour;
149  internal_value.tm_min = minute;
150  internal_value.tm_sec = second;
151  return value(mktime(&internal_value));
152  }
153 
154  drawing::size default_size() const override {return {100, 25};}
155 
159 
160  protected:
161  forms::create_params create_params() const override;
162 
163  drawing::color default_back_color() const override {return xtd::forms::theme_colors::current_theme().window();}
164 
165  drawing::color default_fore_color() const override {return xtd::forms::theme_colors::current_theme().window_text();}
166 
169  virtual void on_value_changed(const event_args& e);
170 
171  void on_handle_created(const event_args& e) override;
172 
173  void wnd_proc(message& message) override;
174 
175  private:
176  void wm_click(message& message);
178  std::chrono::system_clock::time_point max_date_ = std::chrono::system_clock::time_point::max();
179  std::chrono::system_clock::time_point min_date_ = std::chrono::system_clock::time_point::min();
180  std::chrono::system_clock::time_point value_ = std::chrono::system_clock::now();
181  };
182  }
183 }
Represents a picker control that displays available date time along with controls.
Definition: date_time_picker.h:22
virtual control & max_date(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second)
Sets the maximum date and time that can be selected in the control.
Definition: date_time_picker.h:68
drawing::color default_fore_color() const override
Gets the default foreground color of the control.
Definition: date_time_picker.h:165
virtual control & value(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second)
Sets the date/time value assigned to the control.
Definition: date_time_picker.h:143
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
virtual control & value(time_t value)
Sets the date/time value assigned to the control.
Definition: date_time_picker.h:129
virtual control & min_date(const std::tm &min_date)
Sets the minimum date and time that can be selected in the control.
Definition: date_time_picker.h:93
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
virtual control & max_date(int32_t year, int32_t month, int32_t day)
Sets the maximum date and time that can be selected in the control.
Definition: date_time_picker.h:58
virtual control & max_date(const std::tm &max_date)
Sets the maximum date and time that can be selected in the control.
Definition: date_time_picker.h:51
virtual std::chrono::system_clock::time_point value() const
Gets the date/time value assigned to the control.
Definition: date_time_picker.h:123
virtual std::chrono::system_clock::time_point min_date() const
Gets the minimum date and time that can be selected in the control.
Definition: date_time_picker.h:81
virtual control & min_date(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t minute, int32_t second)
Sets the minimum date and time that can be selected in the control.
Definition: date_time_picker.h:110
date_time_picker_format
Specifies the date and time format the date_time_picker control displays.
Definition: date_time_picker_format.h:18
Represents an ARGB (alpha, red, green, blue) color.
Definition: color.h:39
Represents an event.
Definition: event.h:21
drawing::size default_size() const override
Gets the default size of the control.
Definition: date_time_picker.h:154
virtual control & value(int32_t year, int32_t month, int32_t day)
Sets the date/time value assigned to the control.
Definition: date_time_picker.h:138
Implements a Windows message.
Definition: message.h:25
Contains xtd::forms::date_time_picker_format enum class.
Defines the base class for controls, which are components with visual representation.
Definition: control.h:68
virtual control & value(const std::tm &value)
Sets the date/time value assigned to the control.
Definition: date_time_picker.h:132
virtual std::chrono::system_clock::time_point max_date() const
Gets the maximum date and time that can be selected in the control.
Definition: date_time_picker.h:39
virtual control & min_date(time_t min_date)
Sets the minimum date and time that can be selected in the control.
Definition: date_time_picker.h:89
The date_time_picker control displays the date/time value in the long date format set by the user&#39;s o...
Contains xtd::forms::control control.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
virtual control & min_date(int32_t year, int32_t month, int32_t day)
Sets the minimum date and time that can be selected in the control.
Definition: date_time_picker.h:100
virtual date_time_picker_format format() const
Gets the format of the date and time displayed in the control.
Definition: date_time_picker.h:30
virtual control & max_date(time_t max_date)
Sets the maximum date and time that can be selected in the control.
Definition: date_time_picker.h:47
event< date_time_picker, event_handler > value_changed
Occurs when the value of the value property changes.
Definition: date_time_picker.h:158
drawing::color default_back_color() const override
Gets the default background color of the control.
Definition: date_time_picker.h:163