xtd 0.2.0
Loading...
Searching...
No Matches
xtd::forms::settings Class Reference
Inheritance diagram for xtd::forms::settings:
xtd::object

Definition

Represent settings associate to the application.

Header
#include <xtd/forms/settings>
Namespace
xtd::forms
Library
xtd.forms
Remarks
On Windows settings are stored in registry with "HKEY_CURRENT_USER\Software\company_name\product_name" key or if no Company name "\HKEY_CURRENT_USER\Software\Product Name\Product Name" key.
On macos settings are stored in "~/Library/Preferences/product_name Preferences" file.
On linux settings are stored in "~/.product_name" file.
Examples
The following code example demonstrates the use of settings class.
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include "../properties/settings.h"
using namespace xtd::drawing;
using namespace xtd::forms;
auto main()->int {
auto main_form = form::create(settings_example::properties::settings::default_settings().text(), form_start_position::manual);
auto back_color_picker = color_picker::create(main_form, main_form.back_color(), {10, 10}, {75, 25});
back_color_picker.color_picker_changed += [&] {
main_form.back_color(back_color_picker.color());
};
auto save_button = button::create(main_form, "&Save", {90, 10});
save_button.click += [&] {
settings_example::properties::settings::default_settings().size(main_form.client_size());
settings_example::properties::settings::default_settings().location(main_form.location());
settings_example::properties::settings::default_settings().back_color(main_form.back_color());
settings_example::properties::settings::default_settings().save();
};
auto reload_button = button::create(main_form, "&Reload", {170, 10});
reload_button.click += [&] {
settings_example::properties::settings::default_settings().reload();
main_form.client_size(settings_example::properties::settings::default_settings().size());
main_form.location(settings_example::properties::settings::default_settings().location());
main_form.back_color(settings_example::properties::settings::default_settings().back_color());
back_color_picker.color(settings_example::properties::settings::default_settings().back_color());
};
auto reset_button = button::create(main_form, "R&eset", {250, 10});
reset_button.click += [&] {
settings_example::properties::settings::default_settings().reset();
reload_button.perform_click();
};
reload_button.perform_click();
application::run(main_form);
}
static void run()
Begins running a standard application message loop on the current thread, without a form.
static button create()
A factory to create an xtd::forms::button.
static color_picker create()
A factory to create an xtd::forms::color_picker.
event< control, event_handler > click
Occurs when the xtd::forms::control is clicked.
Definition control.h:1471
static form create()
A factory to create an xtd::forms::form.
@ location
Specifies that both the x and y coordinates of the control are defined.
@ size
Specifies that both the width and height property values of the control are defined.
@ text
The xtd::forms::status_bar_panel displays text in the standard font.
@ manual
The position of the form is determined by the Location property.
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.h:11
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.h:12
Examples
settings_example2.cpp.

Public Constructors

 settings ()
 Initializes a new instance of settings class.
 

Public Methods

xtd::ustring read (const xtd::ustring &key, const xtd::ustring &default_value)
 Reads a value for specified key. If not found default value is used.
 
template<typename type_t >
type_t read (const xtd::ustring &key, const type_t &default_value)
 Reads a value for specified key. If not found default value is used.
 
void reset ()
 Reset application settings.
 
void save ()
 Save application settings.
 
void write (const xtd::ustring &key, const xtd::ustring &value)
 Writes a specified value for specified key.
 
template<typename type_t >
void write (const xtd::ustring &key, type_t &&value)
 Writes a specified value for specified key.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
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 >
std::unique_ptr< object_t > memberwise_clone () const noexcept
 Creates a shallow copy of the current object.
 
virtual xtd::ustring to_string () const noexcept
 Returns a sxd::ustring that represents the current object.
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Constructor & Destructor Documentation

◆ settings()

xtd::forms::settings::settings ( )

Initializes a new instance of settings class.

Member Function Documentation

◆ read() [1/2]

template<typename type_t >
type_t xtd::forms::settings::read ( const xtd::ustring key,
const type_t &  default_value 
)
inline

Reads a value for specified key. If not found default value is used.

Template Parameters
type_tThe type of value to read.
Parameters
keyThe key used to read a value.
default_valueA string used if value not found.
Returns
A type_t that represent the value associate to the key.

◆ read() [2/2]

xtd::ustring xtd::forms::settings::read ( const xtd::ustring key,
const xtd::ustring default_value 
)
inline

Reads a value for specified key. If not found default value is used.

Parameters
keyThe key used to read a value.
default_valueA string used if value not found.
Returns
A string that represent the value associate to the key.
Examples
settings_example2.cpp.

◆ reset()

void xtd::forms::settings::reset ( )

Reset application settings.

Examples
settings_example2.cpp.

◆ save()

void xtd::forms::settings::save ( )

Save application settings.

Examples
settings_example2.cpp.

◆ write() [1/2]

void xtd::forms::settings::write ( const xtd::ustring key,
const xtd::ustring value 
)
inline

Writes a specified value for specified key.

Parameters
keyThe key used to write a value.
valueA string to write.
Examples
settings_example2.cpp.

◆ write() [2/2]

template<typename type_t >
void xtd::forms::settings::write ( const xtd::ustring key,
type_t &&  value 
)
inline

Writes a specified value for specified key.

Template Parameters
type_tThe type of value to write.
Parameters
keyThe key used to write a value.
valueA type_t to write.

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