xtd 0.2.0
Loading...
Searching...
No Matches
draw_line.cpp

shows how to draw line in paint event using xtd::drawing::graphics::draw_line.

Windows

macOS

Gnome

#include <xtd/xtd>
namespace draw_line_example {
class form1 : public form {
public:
form1() {
text("Draw line example");
}
protected:
void on_paint(paint_event_args& e) override {
form::on_paint(e);
auto solid_pen = pen {color::red, 5};
e.graphics().draw_line(solid_pen, 10, e.clip_rectangle().height / 7, e.clip_rectangle().width - 20, e.clip_rectangle().height / 7);
auto dot_pen = pen {color::green, 5};
dot_pen.dash_style(drawing_2d::dash_style::dot);
e.graphics().draw_line(dot_pen, 10, e.clip_rectangle().height / 7 * 2, e.clip_rectangle().width - 20, e.clip_rectangle().height / 7 * 2);
auto dash_pen = pen {color::blue, 5};
dash_pen.dash_style(drawing_2d::dash_style::dash);
e.graphics().draw_line(dash_pen, 10, e.clip_rectangle().height / 7 * 3, e.clip_rectangle().width - 20, e.clip_rectangle().height / 7 * 3);
auto dash_dot_pen = pen {color::yellow, 5};
dash_dot_pen.dash_style(drawing_2d::dash_style::dash_dot);
e.graphics().draw_line(dash_dot_pen, 10, e.clip_rectangle().height / 7 * 4, e.clip_rectangle().width - 20, e.clip_rectangle().height / 7 * 4);
auto dash_dot_dot_pen = pen {color::cyan, 5};
dash_dot_dot_pen.dash_style(drawing_2d::dash_style::dash_dot_dot);
e.graphics().draw_line(dash_dot_dot_pen, 10, e.clip_rectangle().height / 7 * 5, e.clip_rectangle().width - 20, e.clip_rectangle().height / 7 * 5);
auto custom_pen = pen {color::magenta, 5};
custom_pen.dash_style(drawing_2d::dash_style::custom);
custom_pen.dash_pattern({4, 1, 3, 2});
e.graphics().draw_line(custom_pen, 10, e.clip_rectangle().height / 7 * 6, e.clip_rectangle().width - 20, e.clip_rectangle().height / 7 * 6);
}
};
}
auto main() -> int {
application::run(draw_line_example::form1 {});
}