xtd 0.2.0
toggle_button2.cpp

demonstrates the use of xtd::forms::check_box control.

Windows

macOS

Gnome

#include <xtd/drawing/pens>
#include <xtd/forms/application>
#include <xtd/forms/form>
#include <xtd/forms/label>
#include <xtd/forms/toggle_button>
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::forms;
class form1 : public form {
public:
form1() {
client_size({280, 180});
controls().push_back_range({button_red, button_green, button_blue, panel_color});
text("Toggle button example");
button_red.location({20, 20});
button_red.image(image_from_color(color::red));
button_red.image_align(content_alignment::middle_left);
button_red.text("Red");
button_red.three_state(true);
button_red.check_state_changed += event_handler(*this, &form1::update_color);
button_green.location({20, 70});
button_green.image(image_from_color(color::lime));
button_green.image_align(content_alignment::middle_left);
button_green.text("Green");
button_green.three_state(true);
button_green.check_state_changed += event_handler(*this, &form1::update_color);
button_blue.location({20, 120});
button_blue.image(image_from_color(color::blue));
button_blue.image_align(content_alignment::middle_left);
button_blue.text("Blue");
button_blue.three_state(true);
button_blue.check_state_changed += event_handler(*this, &form1::update_color);
panel_color.border_style(forms::border_style::fixed_3d);
panel_color.location({150, 20});
panel_color.size({110, 110});
update_color(*this, event_args::empty);
}
private:
void update_color(object& sender, const event_args& e) {
static auto color_levels = std::map<check_state, byte> {{check_state::unchecked, 0_u8}, {check_state::checked, 255_u8}, {check_state::indeterminate, 128_u8}};
panel_color.back_color(color::from_argb(color_levels[button_red.check_state()], color_levels[button_green.check_state()], color_levels[button_blue.check_state()]));
}
image image_from_color(const color& color) {
auto colored_bitmap = bitmap {16, 16};
auto g = graphics::from_image(colored_bitmap);
g.fill_ellipse(solid_brush(color), 0, 0, colored_bitmap.width(), colored_bitmap.height());
g.draw_ellipse(pens::black(), 0, 0, colored_bitmap.width() - 1, colored_bitmap.height() - 1);
return colored_bitmap;
}
toggle_button button_red;
toggle_button button_green;
toggle_button button_blue;
panel panel_color;
};
auto main() -> int {
application::run(form1 {});
}
Encapsulates a GDI+ bitmap, which consists of the pixel data for a graphics image and its attributes....
Definition bitmap.hpp:26
Represents an ARGB (alpha, red, green, blue) color.
Definition color.hpp:46
static const xtd::drawing::color lime
Gets a system-defined color that has an ARGB value of 0xFF00FF00. This field is constant.
Definition color.hpp:287
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 xtd::drawing::color from_argb(uint32 argb) noexcept
Creates a xtd::drawing::color class from a 32-bit ARGB value.
static graphics from_image(const xtd::drawing::image &image)
Creates a new xtd::drawing::graphics from the specified xtd::drawing::image.
An abstract base class that provides functionality for the bitmap and metafile descended classes.
Definition image.hpp:49
static xtd::drawing::pen black()
A system-defined pen object with a width of 1.
Defines a xtd::drawing::brush of a single color. Brushes are used to fill graphics shapes,...
Definition solid_brush.hpp:29
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.hpp:18
static const event_args empty
Provides a value to use with events that do not have event data.
Definition event_args.hpp:25
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
Used to group collections of controls.
Definition panel.hpp:32
Represents a Windows toggle_button.
Definition toggle_button.hpp:44
@ g
The G key.
Definition console_key.hpp:100
@ e
The E key.
Definition console_key.hpp:96
@ checked
The control is checked.
Definition check_state.hpp:27
@ indeterminate
The control is indeterminate. An indeterminate control generally has a shaded appearance.
Definition check_state.hpp:29
@ unchecked
The control is unchecked.
Definition check_state.hpp:25
@ fixed_3d
A three-dimensional border. Same as xtd::forms::border_style::inset.
Definition border_style.hpp:58
@ middle_left
Content is vertically aligned in the middle, and horizontally aligned on the left.
Definition content_alignment.hpp:29
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
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8