xtd 0.2.0
Loading...
Searching...
No Matches
xtd::forms::color_dialog Class Reference
Inheritance diagram for xtd::forms::color_dialog:
xtd::forms::common_dialog xtd::forms::component xtd::object

Definition

Represents a common dialog box that displays available colors along with controls that enable the user to define custom colors.

Header
#include <xtd/forms/color_dialog>
Namespace
xtd::forms
Library
xtd.forms
Remarks
The inherited member show_dialog must be invoked to create this specific common dialog box. hook_proc can be overridden to implement specific dialog box hook functionality. Use color to retrieve the color selected by the user.
When you create an instance of color_dialog, some of the read/write properties are set to initial values. For a list of these values, see the color_dialog constructor.
Appearance
Windows macOS Gnome
Light  
 
 
 
 
 
Dark  
 
 
 
 
 
Examples
The following code example demonstrates the use of color_dialog dialog.
#include <xtd/drawing/drawing_2d/hatch_brush>
#include <xtd/drawing/color_translator>
#include <xtd/drawing/system_colors>
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/color_dialog>
#include <xtd/forms/control_paint>
#include <xtd/forms/form>
#include <xtd/forms/label>
#include <xtd/forms/panel>
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::drawing::drawing_2d;
using namespace xtd::forms;
class form1 : public form {
public:
form1() {
text("Color dialog example");
button1.click += [&] {
auto dialog = color_dialog {};
dialog.color(selected_color);
dialog.custom_colors(custom_colors);
if (dialog.show_dialog(*this) == forms::dialog_result::ok) {
selected_color = dialog.color();
color_label.text(color_translator::to_html(selected_color));
test_zone.invalidate();
}
custom_colors = dialog.custom_colors();
};
test_zone.border_style(border_style::inset).double_buffered(true);
test_zone.paint += [&](object& sender, paint_event_args& e) {
e.graphics().fill_rectangle(hatch_brush {hatch_style::wide_checker_board, color::from_argb(0x66, 0x66, 0x66), color::from_argb(0x99, 0x99, 0x99)}, e.clip_rectangle());
e.graphics().fill_rectangle(solid_brush {selected_color}, e.clip_rectangle());
control_paint::draw_border(test_zone, e.graphics(), test_zone.border_style(), test_zone.border_sides(), application::style_sheet().system_colors().control_text(), e.clip_rectangle());
};
color_label.auto_size(true);
}
private:
color selected_color = system_colors::control();
color_dialog::colors custom_colors = {color::red, color::green, color::blue, color::yellow, system_colors::control()};
button button1 = button::create(*this, "Color...", {10, 10});
panel test_zone = panel::create(*this, {10, 50});
label color_label = label::create(*this, color_translator::to_html(selected_color), {10, 160});
};
auto main() -> int {
application::run(form1 {});
}
Represents an ARGB (alpha, red, green, blue) color.
Definition color.hpp:49
color()=default
Initialize a new instance of xtd::drawing::color class.
Defines a rectangular xtd::drawing::brush with a hatch style, a foreground color, and a background co...
Definition hatch_brush.hpp:32
Defines a xtd::drawing::brush of a single color. Brushes are used to fill graphics shapes,...
Definition solid_brush.hpp:30
static void run()
Begins running a standard application message loop on the current thread, without a form.
Represents a Windows button control.
Definition button.hpp:49
Represents a common dialog box that displays available colors along with controls that enable the use...
Definition color_dialog.hpp:34
std::vector< xtd::drawing::color > colors
Represents an xtd::drawing::color array.
Definition color_dialog.hpp:39
drawing::color color() const noexcept
Gets the color selected by the user.
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
Represents a standard Windows label.
Definition label.hpp:38
Provides data for the xtd::forms::control::paint event.
Definition paint_event_args.hpp:30
Used to group collections of controls.
Definition panel.hpp:32
@ e
The E key.
@ button1
The first button on the message box is the default button.
@ text
The xtd::forms::status_bar_panel displays text in the standard font.
The xtd::drawing::drawing_2d namespace provides advanced two-dimensional and vector graphics function...
Definition compositing_mode.hpp:12
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.hpp:11
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.hpp:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Examples
color_dialog.cpp, and demo.cpp.

Public Types

using colors = std::vector< xtd::drawing::color >
 Represents an xtd::drawing::color array.
 

Public Constructors

 color_dialog ()
 Initializes a new instance of the color_dialog class.
 

Public Properties

bool alpha_color () const noexcept
 Gets a value indicating whether the dialog box shows alpha values and an opacity selector (slider).
 
color_dialogalpha_color (bool alpha_color)
 Sets a value indicating whether the user can use the dialog box to define custom colors.
 
bool allow_full_open () const noexcept
 Gets a value indicating whether the user can use the dialog box to define custom colors.
 
color_dialogallow_full_open (bool allow_full_open)
 Sets a value indicating whether the user can use the dialog box to define custom colors.
 
bool any_color () const noexcept
 Gets a value indicating whether the dialog box displays all available colors in the set of basic colors.
 
color_dialogany_color (bool any_color)
 Sets a value indicating whether the dialog box displays all available colors in the set of basic colors.
 
drawing::color color () const noexcept
 Gets the color selected by the user.
 
color_dialogcolor (const drawing::color &color)
 Sets the color selected by the user.
 
const colorscustom_colors () const noexcept
 Gets the set of custom colors shown in the dialog box.
 
color_dialogcustom_colors (const colors &custom_colors)
 Sets the set of custom colors shown in the dialog box.
 
bool full_open () const noexcept
 Gets a value indicating whether the controls used to create custom colors are visible when the dialog box is opened.
 
color_dialogfull_open (bool full_open)
 Sets a value indicating whether the controls used to create custom colors are visible when the dialog box is opened.
 
size_t options () const noexcept
 Gets values to initialize the color_dialog.
 
bool show_help () const noexcept
 Gets a value indicating whether a Help button appears in the color dialog box.
 
color_dialogshow_help (bool show_help)
 Sets a value indicating whether a Help button appears in the color dialog box.
 
bool solid_color_only () const noexcept
 Gets a value indicating whether the dialog box will restrict users to selecting solid colors only.
 
color_dialogsolid_color_only (bool solid_color_only)
 Sets a value indicating whether the dialog box will restrict users to selecting solid colors only.
 
virtual const xtd::stringtitle () const noexcept
 Gets the color dialog box title.
 
virtual color_dialogtitle (const xtd::string &value)
 Sets the color dialog box title.
 

Public Methods

void reset () noexcept override
 Resets all options to their default values, the last selected color to black, and the custom colors to their default values.
 

Protected Methods

bool run_dialog (intptr owner) override
 When overridden in a derived class, specifies a common dialog box.
 
void run_sheet (intptr owner) override
 When overridden in a derived class, specifies a common dialog box.
 

Additional Inherited Members

- Public Attributes inherited from xtd::forms::common_dialog
event< common_dialog, help_event_handlerhelp_request
 Occurs when the user clicks the Help button on a common dialog box.
 
event< common_dialog, dialog_closed_event_handlerdialog_closed
 Occurs when the user close a common dialog box with dialog close button or other dialog buttons.
 
- Public Member Functions inherited from xtd::forms::common_dialog
 common_dialog ()
 Initializes a new instance of the common_dialog class.
 
xtd::forms::dialog_result dialog_result () const noexcept
 Gets async dialog_result result after dialog box is closing.
 
std::any tag () const noexcept
 Gets an object that contains data about the control.
 
common_dialogtag (const std::any &tag)
 Sets an object that contains data about the control.
 
xtd::forms::dialog_result show_dialog ()
 Runs a common dialog box with a default owner.
 
xtd::forms::dialog_result show_dialog (const iwin32_window &owner)
 Runs a common dialog box with the specified owner.
 
void show_sheet (const iwin32_window &owner)
 Runs a common dialog box with the specified owner.
 
xtd::forms::dialog_result show_sheet_dialog (const iwin32_window &owner)
 Runs a common dialog box with the specified owner.
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
virtual xtd::string to_string () const noexcept
 Returns a xtd::string that represents the current object.
 
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<typename object_a_t , typename object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 
- Protected Member Functions inherited from xtd::forms::common_dialog
virtual void on_dialog_closed (const dialog_closed_event_args &e)
 Raises the common_dialog::dialog_close event.
 
virtual void on_help_request (help_event_args &e)
 Raises the common_dialog::help_request event.
 
void set_dialog_result (xtd::forms::dialog_result value)
 Sets async dialog_result result after dialog box is closing.
 
- Protected Member Functions inherited from xtd::forms::component
 component ()
 Initialises a new instance of the component class.
 
virtual bool can_raise_events () const noexcept
 Gets a value indicating whether the component can raise an event.
 
bool design_mode () const noexcept
 Gets a value that indicates whether the component is currently in design mode.
 

Member Typedef Documentation

◆ colors

Constructor & Destructor Documentation

◆ color_dialog()

xtd::forms::color_dialog::color_dialog ( )

Initializes a new instance of the color_dialog class.

Remarks
When you create an instance of ColorDialog, the following read/write properties are set to initial values.
Property Initial Value
alpha_color true
allow_full_open true
any_color false
color drawing::color::black
custom_colors has no value
full_open false
show_help false
solid_color_only false
You can change the value for any of these properties through a separate call to the property.

Member Function Documentation

◆ alpha_color() [1/2]

bool xtd::forms::color_dialog::alpha_color ( ) const
noexcept

Gets a value indicating whether the dialog box shows alpha values and an opacity selector (slider).

Returns
true if the dialog box shows alpha values and an opacity selector (slider); otherwise, false. The default is true.

◆ alpha_color() [2/2]

color_dialog & xtd::forms::color_dialog::alpha_color ( bool  alpha_color)

Sets a value indicating whether the user can use the dialog box to define custom colors.

Parameters
alpha_colortrue if the dialog box shows alpha values and an opacity selector (slider); otherwise, false.

◆ allow_full_open() [1/2]

bool xtd::forms::color_dialog::allow_full_open ( ) const
noexcept

Gets a value indicating whether the user can use the dialog box to define custom colors.

Returns
true if the user can define custom colors; otherwise, false. The default is true.

◆ allow_full_open() [2/2]

color_dialog & xtd::forms::color_dialog::allow_full_open ( bool  allow_full_open)

Sets a value indicating whether the user can use the dialog box to define custom colors.

Parameters
allow_full_opentrue if the user can define custom colors; otherwise, false. The default is true.

◆ any_color() [1/2]

bool xtd::forms::color_dialog::any_color ( ) const
noexcept

Gets a value indicating whether the dialog box displays all available colors in the set of basic colors.

Returns
true if the dialog box displays all available colors in the set of basic colors; otherwise, false. The default value is false.

◆ any_color() [2/2]

color_dialog & xtd::forms::color_dialog::any_color ( bool  any_color)

Sets a value indicating whether the dialog box displays all available colors in the set of basic colors.

Parameters
any_colortrue if the dialog box displays all available colors in the set of basic colors; otherwise, false. The default value is false.

◆ color() [1/2]

drawing::color xtd::forms::color_dialog::color ( ) const
noexcept

Gets the color selected by the user.

Returns
The color selected by the user. If a color is not selected, the default value is black.
Remarks
The color selected by the user in the dialog box at run time, as defined in color structure.
Examples
color_dialog.cpp, and demo.cpp.

◆ color() [2/2]

color_dialog & xtd::forms::color_dialog::color ( const drawing::color color)

Sets the color selected by the user.

Parameters
colorThe color selected by the user. If a color is not selected.
Remarks
The color selected by the user in the dialog box at run time, as defined in color structure.

◆ custom_colors() [1/2]

const colors & xtd::forms::color_dialog::custom_colors ( ) const
noexcept

Gets the set of custom colors shown in the dialog box.

Returns
A set of custom colors shown by the dialog box. The default value is empty.
Remarks
Users can create their own set of custom colors. These colors are contained in an int32 composed of the BGR (blue, green, red) values necessary to create the color.
Custom colors can only be defined if allow_full_open is set to true.

◆ custom_colors() [2/2]

color_dialog & xtd::forms::color_dialog::custom_colors ( const colors custom_colors)

Sets the set of custom colors shown in the dialog box.

Parameters
custom_colorA set of custom colors shown by the dialog box.
Remarks
Users can create their own set of custom colors. These colors are contained in an int32 composed of the BGR (blue, green, red) values necessary to create the color.
Custom colors can only be defined if allow_full_open is set to true.

◆ full_open() [1/2]

bool xtd::forms::color_dialog::full_open ( ) const
noexcept

Gets a value indicating whether the controls used to create custom colors are visible when the dialog box is opened.

Returns
true if the custom color controls are available when the dialog box is opened; otherwise, false. The default value is false.
Remarks
By default, the custom color controls are not visible when the dialog box is first opened. You must click the Custom Colors button to display them.
Note
If allow_full_open is false, then full_open has no effect.

◆ full_open() [2/2]

color_dialog & xtd::forms::color_dialog::full_open ( bool  full_open)

Sets a value indicating whether the controls used to create custom colors are visible when the dialog box is opened.

Parameters
full_opentrue if the custom color controls are available when the dialog box is opened; otherwise, false. The default value is false.
Remarks
By default, the custom color controls are not visible when the dialog box is first opened. You must click the Custom Colors button to display them.
Note
If allow_full_open is false, then full_open has no effect.

◆ options()

size_t xtd::forms::color_dialog::options ( ) const
noexcept

Gets values to initialize the color_dialog.

Returns
A bitwise combination of internal values that initializes the color_dialog.
Remarks
The options property corresponds to the flags used to initialize a color dialog box using Win32. Use the properties of the color_dialog class to get and set the options.

◆ show_help() [1/2]

bool xtd::forms::color_dialog::show_help ( ) const
noexcept

Gets a value indicating whether a Help button appears in the color dialog box.

Returns
true if the Help button is shown in the dialog box; otherwise, false. The default value is false.

◆ show_help() [2/2]

color_dialog & xtd::forms::color_dialog::show_help ( bool  show_help)

Sets a value indicating whether a Help button appears in the color dialog box.

Parameters
show_helptrue if the Help button is shown in the dialog box; otherwise, false.

◆ solid_color_only() [1/2]

bool xtd::forms::color_dialog::solid_color_only ( ) const
noexcept

Gets a value indicating whether the dialog box will restrict users to selecting solid colors only.

Returns
true if users can select only solid colors; otherwise, false. The default value is false.
Remarks
This property is applicable to systems with 256 or fewer colors. On these types of systems, some colors are composites of others.

◆ solid_color_only() [2/2]

color_dialog & xtd::forms::color_dialog::solid_color_only ( bool  solid_color_only)

Sets a value indicating whether the dialog box will restrict users to selecting solid colors only.

Parameters
solid_color_onlytrue if users can select only solid colors; otherwise, false.
Remarks
This property is applicable to systems with 256 or fewer colors. On these types of systems, some colors are composites of others.

◆ title() [1/2]

virtual const xtd::string & xtd::forms::color_dialog::title ( ) const
virtualnoexcept

Gets the color dialog box title.

Returns
The color dialog box title. The default value is an empty string ("").
Remarks
The string is placed in the title bar of the dialog box. If the title is an empty string, the system uses a default title, which is "Color".

◆ title() [2/2]

virtual color_dialog & xtd::forms::color_dialog::title ( const xtd::string value)
virtual

Sets the color dialog box title.

Parameters
valueThe file dialog box title. The default value is an empty string ("").
Returns
Current file_dialog.
Remarks
The string is placed in the title bar of the dialog box. If the title is an empty string, the system uses a default title, which is "Color".

◆ reset()

void xtd::forms::color_dialog::reset ( )
overridevirtualnoexcept

Resets all options to their default values, the last selected color to black, and the custom colors to their default values.

Implements xtd::forms::common_dialog.

◆ run_dialog()

bool xtd::forms::color_dialog::run_dialog ( intptr  owner)
overrideprotectedvirtual

When overridden in a derived class, specifies a common dialog box.

Parameters
ownerA value that represents the window handle of the owner window for the common dialog box.
Returns
true if the dialog box was successfully run; otherwise, false.

Implements xtd::forms::common_dialog.

◆ run_sheet()

void xtd::forms::color_dialog::run_sheet ( intptr  owner)
overrideprotectedvirtual

When overridden in a derived class, specifies a common dialog box.

Parameters
ownerA value that represents the window handle of the owner window for the common dialog box.

Implements xtd::forms::common_dialog.


The documentation for this class was generated from the following file: