The Wiggly example shows how to animate a user control using timer and timer::tick event. In addition, the example demonstrates how to use graphics::measure_string to determine the size of text on screen.
#include <xtd/drawing/system_colors>
#include <xtd/forms/application>
#include <xtd/forms/form>
#include <xtd/forms/text_box>
#include <xtd/forms/timer>
#include <xtd/forms/user_control>
using namespace std;
namespace wiggly_example {
public:
wiggly() {
back_color(system_colors::window());
}
protected:
static const vector sins = {0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38};
auto wiggly_text = as<u32string>(
text());
for (
auto i = 0_sz;
i < wiggly_text.length();
i++) {
auto index = (step +
i) % sins.size();
}
}
private:
void on_timer_tick(
object& sender,
const event_args& e) {
step++;
invalidate();
}
int step = 0;
};
class form1 :
public form {
public:
form1() {
client_size({330, 130});
controls().push_back_range({wiggly,
text_box});
};
text_box.
anchor(anchor_styles::left | anchor_styles::bottom | anchor_styles::right);
wiggly.bounds({20, 20, 290, 60});
wiggly.anchor(anchor_styles::top | anchor_styles::left | anchor_styles::right | anchor_styles::bottom);
}
private:
wiggly_example::wiggly wiggly;
};
}
auto main()->int {
application::run(wiggly_example::form1 {});
}