#define TRACE
#include <xtd/forms/application>
#include <xtd/forms/form>
#include <xtd/forms/text_box>
#include <xtd/ctrace>
#include <xtd/environment>
namespace numeric_tex_box_example {
class numeric_text_box :
public text_box {
public:
numeric_text_box() = default;
double value() const {
auto result = .0;
try_parse(text(), result);
return result;
}
protected:
text_box::on_key_press(e);
e.handled((!isdigit(e.key_char()) && e.key_char() != '.') || (e.key_char() == '.' && as<string>(text()).index_of('.') != string::npos));
}
void on_text_changed(
const event_args& e)
override {
text_box::on_text_changed(e);
on_value_changed(e);
}
value_changed(*this, e);
}
private:
using text_box::text;
};
class form1 :
public form {
public:
form1() {
text("Numeric text box example");
numeric_text_box1.parent(*this);
numeric_text_box1.value(42);
numeric_text_box1.location({10, 10});
numeric_text_box1.value_changed += [&] {
ctrace << string::format("value_changed [value={}]", numeric_text_box1.value()) << environment::new_line;
};
}
private:
numeric_text_box numeric_text_box1;
};
}
auto main() -> int {
application::run(numeric_tex_box_example::form1 {});
}
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.h:18
Represents an event.
Definition event.h:21
Represents a standard Windows text box.
Definition text_box.h:31
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition to_string.h:41
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10