xtd 0.2.0
draw_line.cpp

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

Windows

macOS

Gnome

#include <xtd/forms/application>
#include <xtd/forms/form>
using namespace xtd::drawing;
using namespace xtd::drawing::drawing_2d;
using namespace xtd::forms;
namespace draw_line_example {
class form1 : public form {
public:
form1() {
text("Draw line example");
}
protected:
void on_paint(paint_event_args& e) override {
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};
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};
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};
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};
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_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 {});
}
static const xtd::drawing::color yellow
Gets a system-defined color that has an ARGB value of 0xFFFFFF00. This field is constant.
Definition color.hpp:476
static const xtd::drawing::color green
Gets a system-defined color that has an ARGB value of 0xFF008000. This field is constant.
Definition color.hpp:212
static const xtd::drawing::color red
Gets a system-defined color that has an ARGB value of 0xFFFF0000. This field is constant.
Definition color.hpp:401
static const xtd::drawing::color blue
Gets a system-defined color that has an ARGB value of 0xFF0000FF. This field is constant.
Definition color.hpp:86
static const xtd::drawing::color cyan
Gets a system-defined color that has an ARGB value of 0xFF00FFFF. This field is constant.
Definition color.hpp:119
static const xtd::drawing::color magenta
Gets a system-defined color that has an ARGB value of 0xFFFF00FF. This field is constant.
Definition color.hpp:296
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition pen.hpp:32
xtd::drawing::drawing_2d::dash_style dash_style() const noexcept
Gets the style used for dashed lines drawn with this xtd::drawing::pen.
static void run()
Begins running a standard application message loop on the current thread, without a form.
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
void on_paint(paint_event_args &e) override
Raises the xtd::forms::control::paint event.
Provides data for the xtd::forms::control::paint event.
Definition paint_event_args.hpp:30
@ e
The E key.
Definition console_key.hpp:96
@ dash_dot
Specifies a line consisting of a repeating pattern of dash-dot.
Definition dash_style.hpp:28
@ dot
Specifies a line consisting of dots.
Definition dash_style.hpp:26
@ custom
Specifies a user-defined custom dash style.
Definition dash_style.hpp:32
@ dash
Specifies a line consisting of dashes.
Definition dash_style.hpp:24
@ dash_dot_dot
Specifies a line consisting of a repeating pattern of dash-dot-dot.
Definition dash_style.hpp:30
The xtd::drawing::drawing_2d namespace provides advanced two-dimensional and vector graphics function...
Definition compositing_mode.hpp:12
The xtd::drawing::text namespace provides advanced GDI+ typography functionality.
Definition font_collection.hpp:14
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.hpp:10
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:217