xtd 0.2.0
Loading...
Searching...
No Matches
xtd::forms::control::control_collection Class Reference
Inheritance diagram for xtd::forms::control::control_collection:
xtd::forms::layout::arranged_element_collection< control_ref > xtd::object

Definition

Represents a collection of controls.

Public Aliases

using base
 Represents the base type of the collection.
 

Public Constructors

 control_collection ()=default
 Creates a new object xtd::forms::control::control_collection with specified allocator (optional).
 
 control_collection (bool keep_cloned_controls)
 Creates a new object xtd::forms::control::control_collection with specified keep_cloned_controls, and allocator (optional).
 

Operators

std::optional< value_type > operator[] (const xtd::string &name) const
 Gets the first xtd::forms::control::control_collection in the list with the specified name.
 
std::optional< value_type > operator[] (const xtd::string &name)
 Gets the first xtd::forms::control::control_collection in the list with the specified name.
 

Public Methods

void add (const control_ref &value) override
 
template<class control_t>
void add (control_t &value)
 
template<class control_t, class ... args_t>
control_t & emplace_front (args_t &&...args)
 Creates and inserts specified control at specified position.
 
template<class control_t, class ... args_t>
control_t & emplace_at (size_t index, args_t &&...args)
 Creates and inserts specified control at specified position.
 
template<class control_t, class ... args_t>
control_t & emplace_back (args_t &&...args)
 Creates and adds a control to the end.
 
void insert (size_t index, const control_ref &value) override
 Inserts specified element at specified index.
 
template<class control_t>
void insert (size_t index, control_t &value)
 

Public Deprecated Methods

template<class control_t>
void push_back (control_t &value)
 

Protected Methods

void on_item_removed (size_t index, control_ref &item) override
 Raises the xtd::forms::layout::arranged_element_collection::item_removed event.
 

Additional Inherited Members

using base_type
 Represents the list base type.
 
using const_base_type
 Represents the list base type.
 
using size_type
 Represents the list size type (usually xtd::size).
 
using reference
 Represents the reference of list value type.
 
using const_reference
 Represents the const reference of list value type.
 
using pointer
 Represents the pointer of list value type.
 
using const_pointer
 Represents the const pointer of list value type.
 
using read_only_collection
 Represents the read only collection of of list.
 
using base_type
 Represents the list base type.
 
using const_base_type
 Represents the list base type.
 
using size_type
 Represents the list size type (usually xtd::size).
 
using reference
 Represents the reference of list value type.
 
using const_reference
 Represents the const reference of list value type.
 
using pointer
 Represents the pointer of list value type.
 
using const_pointer
 Represents the const pointer of list value type.
 
using read_only_collection
 Represents the read only collection of of list.
 
event< arranged_element_collection, delegate< void(size_t, control_ref &item)> > item_added
 Occurs when an item is added to the collection.
 
event< arranged_element_collection, delegate< void(size_t, control_ref &item)> > item_updated
 Occurs when an item is updated in the collection.
 
event< arranged_element_collection, delegate< void(size_t, control_ref &item)> > item_removed
 Occurs when an item is removed from the collection.
 
event< arranged_element_collection, delegate< void(size_t, control_ref &item)> > item_added
 Occurs when an item is added to the collection.
 
event< arranged_element_collection, delegate< void(size_t, control_ref &item)> > item_updated
 Occurs when an item is updated in the collection.
 
event< arranged_element_collection, delegate< void(size_t, control_ref &item)> > item_removed
 Occurs when an item is removed from the collection.
 
static constexpr xtd::size npos
 Represents a value that is not a valid position in a collection.
 
static constexpr xtd::size bpos
 Represents the index of the first valid element in a collection.
 
static constexpr xtd::size epos
 Represents the index of the last valid element in a collection.
 
static constexpr xtd::size npos
 Represents a value that is not a valid position in a collection.
 
static constexpr xtd::size bpos
 Represents the index of the first valid element in a collection.
 
static constexpr xtd::size epos
 Represents the index of the last valid element in a collection.
 
 arranged_element_collection ()=default
 Initializes a new instance of the xtd::forms::layout::arranged_element_collection class that is empty.
 
 arranged_element_collection (size_type capacity)
 Constructs the container with specified count default-inserted instances of type_t. No copies are made.
 
 arranged_element_collection (const xtd::collections::generic::ienumerable< control_ref > &collection)
 Initializes a new instance of the xtd::forms::layout::arranged_element_collection <type_t> class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied.
 
 arranged_element_collection (const arranged_element_collection &collection)
 Default copy constructor with specified list.
 
 arranged_element_collection (arranged_element_collection &&collection)
 Move constructor with specified list.
 
 arranged_element_collection (const base_type &collection)
 Copy constructor with specified base type list.
 
 arranged_element_collection (base_type &&collection)
 Move constructor with specified base type list.
 
 arranged_element_collection (std::initializer_list< control_ref > items)
 Constructs the container with the contents of the specified initializer list, and allocator.
 
 arranged_element_collection (input_iterator_t first, input_iterator_t last)
 Constructs the container with the contents of the range [first, last).
 
 arranged_element_collection ()=default
 Initializes a new instance of the xtd::forms::layout::arranged_element_collection class that is empty.
 
 arranged_element_collection (size_type capacity)
 Constructs the container with specified count default-inserted instances of type_t. No copies are made.
 
 arranged_element_collection (const xtd::collections::generic::ienumerable< control_ref > &collection)
 Initializes a new instance of the xtd::forms::layout::arranged_element_collection <type_t> class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied.
 
 arranged_element_collection (const arranged_element_collection &collection)
 Default copy constructor with specified list.
 
 arranged_element_collection (arranged_element_collection &&collection)
 Move constructor with specified list.
 
 arranged_element_collection (const base_type &collection)
 Copy constructor with specified base type list.
 
 arranged_element_collection (base_type &&collection)
 Move constructor with specified base type list.
 
 arranged_element_collection (std::initializer_list< control_ref > items)
 Constructs the container with the contents of the specified initializer list, and allocator.
 
 arranged_element_collection (input_iterator_t first, input_iterator_t last)
 Constructs the container with the contents of the range [first, last).
 
size_type capacity () const noexcept
 Gets the total number of elements the internal data structure can hold without resizing.
 
void capacity (size_type value)
 Sets the total number of elements the internal data structure can hold without resizing.
 
size_type count () const noexcept override
 Gets the number of elements contained in the xtd::forms::layout::arranged_element_collection <type_t>.
 
pointer data ()
 Direct access to the underlying array.
 
const_pointer data () const
 Direct access to the underlying array.
 
const auto & items () const
 Returns the underlying base type items.
 
auto & items ()
 Returns the underlying base type items.
 
virtual bool sorted () const noexcept
 Checks whether the container is sorted.
 
virtual arranged_element_collectionsorted (bool value)
 Sets the container is sorted.
 
size_type capacity () const noexcept
 Gets the total number of elements the internal data structure can hold without resizing.
 
void capacity (size_type value)
 Sets the total number of elements the internal data structure can hold without resizing.
 
size_type count () const noexcept override
 Gets the number of elements contained in the xtd::forms::layout::arranged_element_collection <type_t>.
 
pointer data ()
 Direct access to the underlying array.
 
const_pointer data () const
 Direct access to the underlying array.
 
const auto & items () const
 Returns the underlying base type items.
 
auto & items ()
 Returns the underlying base type items.
 
virtual bool sorted () const noexcept
 Checks whether the container is sorted.
 
virtual arranged_element_collectionsorted (bool value)
 Sets the container is sorted.
 
void add (const control_ref &item) override
 Adds an item to the xtd::forms::layout::arranged_element_collection <type_t>.
 
virtual void add (control_ref &&item)
 Adds an item to the xtd::forms::layout::arranged_element_collection <type_t>.
 
virtual void add_range (const arranged_element_collection &collection)
 Adds elements to the end.
 
virtual void add_range (const std::vector< control_ref > &collection)
 Adds elements to the end.
 
virtual void add_range (const std::initializer_list< control_ref > &collection)
 Adds elements to the end.
 
void add_range (collection_t &&collection)
 Adds elements to the end.
 
void add_range (const collection_t &collection)
 Adds elements to the end.
 
void clear () override
 Removes all items from the xtd::forms::layout::arranged_element_collection <type_t>.
 
bool contains (const control_ref &item) const noexcept override
 Determines whether the xtd::forms::layout::arranged_element_collection <type_t> contains a specific value.
 
void copy_to (xtd::array< control_ref > &array, xtd::size array_index) const override
 Copies the elements of the xtd::forms::layout::arranged_element_collection <type_t> to an xtd::array, starting at a particular xtd::array index.
 
xtd::collections::generic::enumerator< control_refget_enumerator () const noexcept override
 Returns an enumerator that iterates through the xtd::forms::layout::arranged_element_collection <type_t>.
 
virtual arranged_element_collectionsort ()
 Sorts the content.
 
bool remove (const control_ref &item) override
 Removes the first occurrence of a specific object from the xtd::forms::layout::arranged_element_collection <type_t>.
 
virtual void remove_at (size_t index)
 Erases element at specified index.
 
xtd::array< control_refto_array () const noexcept
 Gets an array with the elements of the container.
 
void add (const control_ref &item) override
 Adds an item to the xtd::forms::layout::arranged_element_collection <type_t>.
 
virtual void add (control_ref &&item)
 Adds an item to the xtd::forms::layout::arranged_element_collection <type_t>.
 
virtual void add_range (const arranged_element_collection &collection)
 Adds elements to the end.
 
virtual void add_range (const std::vector< control_ref > &collection)
 Adds elements to the end.
 
virtual void add_range (const std::initializer_list< control_ref > &collection)
 Adds elements to the end.
 
void add_range (collection_t &&collection)
 Adds elements to the end.
 
void add_range (const collection_t &collection)
 Adds elements to the end.
 
void clear () override
 Removes all items from the xtd::forms::layout::arranged_element_collection <type_t>.
 
bool contains (const control_ref &item) const noexcept override
 Determines whether the xtd::forms::layout::arranged_element_collection <type_t> contains a specific value.
 
void copy_to (xtd::array< control_ref > &array, xtd::size array_index) const override
 Copies the elements of the xtd::forms::layout::arranged_element_collection <type_t> to an xtd::array, starting at a particular xtd::array index.
 
xtd::collections::generic::enumerator< control_refget_enumerator () const noexcept override
 Returns an enumerator that iterates through the xtd::forms::layout::arranged_element_collection <type_t>.
 
virtual arranged_element_collectionsort ()
 Sorts the content.
 
bool remove (const control_ref &item) override
 Removes the first occurrence of a specific object from the xtd::forms::layout::arranged_element_collection <type_t>.
 
virtual void remove_at (size_t index)
 Erases element at specified index.
 
xtd::array< control_refto_array () const noexcept
 Gets an array with the elements of the container.
 
arranged_element_collectionoperator= (const arranged_element_collection &other)
 Copy assignment operator. Replaces the contents with a copy of the contents of other.
 
arranged_element_collectionoperator= (arranged_element_collection &&other) noexcept
 Move assignment operator. Replaces the contents with those of other using move semantics (i.e. the data in other is moved from other into this container). other is in a valid but unspecified state afterwards.
 
arranged_element_collectionoperator= (const std::initializer_list< control_ref > &items)
 Replaces the contents with those identified by initializer list ilist.
 
value_type & operator[] (size_type index)
 Access specified element.
 
const value_type & operator[] (size_type index) const
 Access specified element.
 
 operator const_base_type & () const noexcept
 Returns a reference to the underlying base type.
 
 operator base_type & () noexcept
 Returns a reference to the underlying base type.
 
bool operator== (const arranged_element_collection &value) const
 
bool operator!= (const arranged_element_collection &value) const
 
arranged_element_collectionoperator= (const arranged_element_collection &other)
 Copy assignment operator. Replaces the contents with a copy of the contents of other.
 
arranged_element_collectionoperator= (arranged_element_collection &&other) noexcept
 Move assignment operator. Replaces the contents with those of other using move semantics (i.e. the data in other is moved from other into this container). other is in a valid but unspecified state afterwards.
 
arranged_element_collectionoperator= (const std::initializer_list< control_ref > &items)
 Replaces the contents with those identified by initializer list ilist.
 
value_type & operator[] (size_type index)
 Access specified element.
 
const value_type & operator[] (size_type index) const
 Access specified element.
 
 operator const_base_type & () const noexcept
 Returns a reference to the underlying base type.
 
 operator base_type & () noexcept
 Returns a reference to the underlying base type.
 
bool operator== (const arranged_element_collection &value) const
 
bool operator!= (const arranged_element_collection &value) const
 
size_type max_size () const noexcept
 Returns the maximum possible number of elements.
 
size_type max_size () const noexcept
 Returns the maximum possible number of elements.
 
reference at (size_type pos)
 Access specified element with bounds checking.
 
const_reference at (size_type pos) const
 Access specified element with bounds checking.
 
reference back ()
 Access the last element.
 
const_reference back () const
 Access the last element.
 
const_reverse_iterator crbegin () const noexcept
 Returns a reverse iterator to the end.
 
const_reverse_iterator crend () const noexcept
 Returns a reverse iterator to the end.
 
reference front ()
 Access the first element.
 
const_reference front () const
 Access the first element.
 
auto get_allocator () const noexcept
 Returns the associated allocator.
 
void emplace (xtd::collections::generic::list< value_type >::const_iterator pos, args_t &&... args)
 Inserts specified element at specified position.
 
void emplace_back (args_t &&... args)
 Adds an element to the end.
 
auto erase (xtd::collections::generic::list< value_type >::iterator pos)
 Erases element at specified position.
 
auto erase (xtd::collections::generic::list< value_type >::const_iterator pos)
 Erases element at specified position.
 
auto erase (xtd::collections::generic::list< value_type >::iterator first, xtd::collections::generic::list< value_type >::iterator last)
 Erases elements at specified range.
 
auto erase (xtd::collections::generic::list< value_type >::const_iterator first, xtd::collections::generic::list< value_type >::const_iterator last)
 Erases elements at specified range.
 
void erase_at (size_t index)
 Erases element at specified index.
 
auto insert (xtd::collections::generic::list< value_type >::const_iterator pos, const control_ref &value)
 Inserts specified element at specified position.
 
auto insert (xtd::collections::generic::list< value_type >::const_iterator pos, control_ref &&value)
 Inserts specified element at specified position.
 
void insert_at (size_t index, const control_ref &value)
 Inserts specified element at specified index.
 
void pop_back ()
 Removes the last element of the container.
 
void push_back (const control_ref &item)
 Adds an element to the end.
 
void push_back (control_ref &&item)
 Adds an element to the end.
 
void push_back_range (const arranged_element_collection &collection)
 Adds elements to the end.
 
void push_back_range (const std::vector< control_ref > &collection)
 Adds elements to the end.
 
void push_back_range (const std::initializer_list< control_ref > &collection)
 Adds elements to the end.
 
void push_back_range (collection_t &&collection)
 Adds elements to the end.
 
void push_back_range (iterator_t begin, iterator_t end)
 Adds elements to the end.
 
std::vector< control_refto_vector () const noexcept
 Gets an array with the elements of the container.
 
auto rbegin () noexcept
 Returns a reverse iterator to the end.
 
auto rbegin () const noexcept
 Returns a reverse iterator to the end.
 
auto rend () noexcept
 Returns a reverse iterator to the end.
 
auto rend () const noexcept
 Returns a reverse iterator to the end.
 
void reserve (size_type size)
 Reserves storage.
 
void shrink_to_fit ()
 Reduces memory usage by freeing unused memory.
 
auto insert (xtd::collections::generic::list< value_type >::const_iterator pos, const control_ref &value)
 Inserts specified element at specified position.
 
auto insert (xtd::collections::generic::list< value_type >::const_iterator pos, control_ref &&value)
 Inserts specified element at specified position.
 
reference at (size_type pos)
 Access specified element with bounds checking.
 
const_reference at (size_type pos) const
 Access specified element with bounds checking.
 
reference back ()
 Access the last element.
 
const_reference back () const
 Access the last element.
 
const_reverse_iterator crbegin () const noexcept
 Returns a reverse iterator to the end.
 
const_reverse_iterator crend () const noexcept
 Returns a reverse iterator to the end.
 
reference front ()
 Access the first element.
 
const_reference front () const
 Access the first element.
 
auto get_allocator () const noexcept
 Returns the associated allocator.
 
void emplace (xtd::collections::generic::list< value_type >::const_iterator pos, args_t &&... args)
 Inserts specified element at specified position.
 
void emplace_back (args_t &&... args)
 Adds an element to the end.
 
auto erase (xtd::collections::generic::list< value_type >::iterator pos)
 Erases element at specified position.
 
auto erase (xtd::collections::generic::list< value_type >::const_iterator pos)
 Erases element at specified position.
 
auto erase (xtd::collections::generic::list< value_type >::iterator first, xtd::collections::generic::list< value_type >::iterator last)
 Erases elements at specified range.
 
auto erase (xtd::collections::generic::list< value_type >::const_iterator first, xtd::collections::generic::list< value_type >::const_iterator last)
 Erases elements at specified range.
 
void erase_at (size_t index)
 Erases element at specified index.
 
void insert_at (size_t index, const control_ref &value)
 Inserts specified element at specified index.
 
void pop_back ()
 Removes the last element of the container.
 
void push_back (const control_ref &item)
 Adds an element to the end.
 
void push_back (control_ref &&item)
 Adds an element to the end.
 
void push_back_range (const arranged_element_collection &collection)
 Adds elements to the end.
 
void push_back_range (const std::vector< control_ref > &collection)
 Adds elements to the end.
 
void push_back_range (const std::initializer_list< control_ref > &collection)
 Adds elements to the end.
 
void push_back_range (collection_t &&collection)
 Adds elements to the end.
 
void push_back_range (iterator_t begin, iterator_t end)
 Adds elements to the end.
 
std::vector< control_refto_vector () const noexcept
 Gets an array with the elements of the container.
 
auto rbegin () noexcept
 Returns a reverse iterator to the end.
 
auto rbegin () const noexcept
 Returns a reverse iterator to the end.
 
auto rend () noexcept
 Returns a reverse iterator to the end.
 
auto rend () const noexcept
 Returns a reverse iterator to the end.
 
void reserve (size_type size)
 Reserves storage.
 
void shrink_to_fit ()
 Reduces memory usage by freeing unused memory.
 
 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 xtd::size 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<class object_t>
xtd::unique_ptr_object< 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.
 
template<class object_a_t, class 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<class object_a_t, class 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.
 
virtual void on_item_added (size_t index, control_ref &item)
 Raises the xtd::forms::layout::arranged_element_collection::item_added event.
 
virtual void on_item_updated (size_t index, control_ref &item)
 Raises the xtd::forms::layout::arranged_element_collection::item_updated event.
 
virtual void on_item_added (size_t index, control_ref &item)
 Raises the xtd::forms::layout::arranged_element_collection::item_added event.
 
virtual void on_item_updated (size_t index, control_ref &item)
 Raises the xtd::forms::layout::arranged_element_collection::item_updated event.
 

Member Typedef Documentation

◆ base

Represents the base type of the collection.

Constructor & Destructor Documentation

◆ control_collection() [1/2]

xtd::forms::control::control_collection::control_collection ( )
explicitdefault

Creates a new object xtd::forms::control::control_collection with specified allocator (optional).

Remarks
If allocator not specified, the std::allocator<value_type> is used.

◆ control_collection() [2/2]

xtd::forms::control::control_collection::control_collection ( bool keep_cloned_controls)
explicit

Creates a new object xtd::forms::control::control_collection with specified keep_cloned_controls, and allocator (optional).

Parameters
keep_cloned_controlsIf true the collection clone and keep controls; otherwise none.
Remarks
If allocator not specified, the std::allocator<value_type> is used.
Warning
Internal use only

Member Function Documentation

◆ operator[]() [1/2]

std::optional< value_type > xtd::forms::control::control_collection::operator[] ( const xtd::string & name) const

Gets the first xtd::forms::control::control_collection in the list with the specified name.

Parameters
nameThe name of the xtd::forms::control to get from the list.
Returns
The first xtd::forms::control in the list with the given Name. This item returns optional with no value if no xtd::forms::control with the given name can be found.
Remarks
The operator [] property is case-sensitive when searching for names. That is, if two controls exist with the names "Lname" and "lname", operator [] property will find only the xtd::forms::control with the xtd::forms::control::name() that you specify, not both.

◆ operator[]() [2/2]

std::optional< value_type > xtd::forms::control::control_collection::operator[] ( const xtd::string & name)

Gets the first xtd::forms::control::control_collection in the list with the specified name.

Parameters
nameThe name of the xtd::forms::control to get from the list.
Returns
The first xtd::forms::control in the list with the given Name. This item returns optional with no value if no xtd::forms::control with the given name can be found.
Remarks
The operator [] property is case-sensitive when searching for names. That is, if two controls exist with the names "Lname" and "lname", operator [] property will find only the xtd::forms::control with the xtd::forms::control::name() that you specify, not both.

◆ emplace_front()

template<class control_t, class ... args_t>
control_t & xtd::forms::control::control_collection::emplace_front ( args_t &&... args)
inline

Creates and inserts specified control at specified position.

Parameters
posThe iterator before which the content will be inserted. pos may be the xtd::forms::control::control_collection::end iterator.
argsThe arguments to forward to the create method of the control
Returns
A reference to the created control.
Remarks
The control will be destroyed automatically when the control no longer has a parent.
For creation and insertion, this method uses the xtd::forms::control::create methods of the various controls.
Examples
The folowing example demonstartes the use of xtd::forms::control::control_collection::emplace, xtd::forms::control::control_collection::emplace_at and xtd::forms::control::control_collection::emplace_back methods.
#include <xtd/xtd>
auto main() -> int {
auto button1_clicked = 0, button2_clicked = 0;
auto form1 = form::create("Emplace example");
form1.controls().emplace_front<button>("Button 1", point{50, 50}).click += delegate_ {
form1.controls()["label1"].value().get().text(string::format("Button 1 clicked {} times", ++button1_clicked));
};
form1.controls().emplace_at<button>(1, "Button 2", point {50, 100}, drawing::size {200, 75}).auto_repeat(true).click += delegate_ {
form1.controls()["label2"].value().get().text(string::format("Button 2 clicked {} times", ++button2_clicked));
};
form1.controls().emplace_at<label>(2, "Button 1 clicked 0 times", point {50, 200}, drawing::size {200, 23}, "label1");
form1.controls().emplace_back<label>("Button 2 clicked 0 times", point {50, 230}, drawing::size {200, 23}, "label2");
application::run(form1);
}
Represents a Windows button control.
Definition button.hpp:49
event< control, event_handler > click
Occurs when the xtd::forms::control is clicked.
Definition control.hpp:1488
static form create()
A factory to create an xtd::forms::form.
#define delegate_
The declaration of a delegate type is similar to a method signature. It has a return value and any nu...
Definition delegate.hpp:900
xtd::forms::style_sheets::control label
The label data allows you to specify the box of a label control.
Definition label.hpp:25
@ point
Specifies a printer's point (1/72 inch) as the unit of measure.
Definition graphics_unit.hpp:25
Stores an ordered pair of integers, which specify a height and width.
Definition size.hpp:32

◆ emplace_at()

template<class control_t, class ... args_t>
control_t & xtd::forms::control::control_collection::emplace_at ( size_t index,
args_t &&... args )
inline

Creates and inserts specified control at specified position.

Parameters
indexThe index before which the content will be inserted.
argsThe arguments to forward to the create method of the control
Returns
A reference to the created control.
Remarks
The control will be destroyed automatically when the control no longer has a parent.
For creation and insertion, this method uses the xtd::forms::control::create methods of the various controls.
Examples
The folowing example demonstartes the use of xtd::forms::control::control_collection::emplace, xtd::forms::control::control_collection::emplace_at and xtd::forms::control::control_collection::emplace_back methods.
#include <xtd/xtd>
auto main() -> int {
auto button1_clicked = 0, button2_clicked = 0;
auto form1 = form::create("Emplace example");
form1.controls().emplace_front<button>("Button 1", point{50, 50}).click += delegate_ {
form1.controls()["label1"].value().get().text(string::format("Button 1 clicked {} times", ++button1_clicked));
};
form1.controls().emplace_at<button>(1, "Button 2", point {50, 100}, drawing::size {200, 75}).auto_repeat(true).click += delegate_ {
form1.controls()["label2"].value().get().text(string::format("Button 2 clicked {} times", ++button2_clicked));
};
form1.controls().emplace_at<label>(2, "Button 1 clicked 0 times", point {50, 200}, drawing::size {200, 23}, "label1");
form1.controls().emplace_back<label>("Button 2 clicked 0 times", point {50, 230}, drawing::size {200, 23}, "label2");
application::run(form1);
}

◆ emplace_back()

template<class control_t, class ... args_t>
control_t & xtd::forms::control::control_collection::emplace_back ( args_t &&... args)
inline

Creates and adds a control to the end.

Parameters
argsThe arguments to forward to the create method of the control
Returns
A reference to the created control.
Remarks
The control will be destroyed automatically when the control no longer has a parent.
For creation and insertion, this method uses the xtd::forms::control::create methods of the various controls.
Examples
The folowing example demonstartes the use of xtd::forms::control::control_collection::emplace, xtd::forms::control::control_collection::emplace_at and xtd::forms::control::control_collection::emplace_back methods.
#include <xtd/xtd>
auto main() -> int {
auto button1_clicked = 0, button2_clicked = 0;
auto form1 = form::create("Emplace example");
form1.controls().emplace_front<button>("Button 1", point{50, 50}).click += delegate_ {
form1.controls()["label1"].value().get().text(string::format("Button 1 clicked {} times", ++button1_clicked));
};
form1.controls().emplace_at<button>(1, "Button 2", point {50, 100}, drawing::size {200, 75}).auto_repeat(true).click += delegate_ {
form1.controls()["label2"].value().get().text(string::format("Button 2 clicked {} times", ++button2_clicked));
};
form1.controls().emplace_at<label>(2, "Button 1 clicked 0 times", point {50, 200}, drawing::size {200, 23}, "label1");
form1.controls().emplace_back<label>("Button 2 clicked 0 times", point {50, 230}, drawing::size {200, 23}, "label2");
application::run(form1);
}

◆ insert()

void xtd::forms::control::control_collection::insert ( size_t index,
const control_ref & value )
overridevirtual

Inserts specified element at specified index.

Parameters
indexThe index before which the content will be inserted.
valueThe element to insert.

Reimplemented from xtd::forms::layout::arranged_element_collection< control_ref >.

◆ on_item_removed()

void xtd::forms::control::control_collection::on_item_removed ( size_t index,
control_ref & item )
inlineoverrideprotectedvirtual

Raises the xtd::forms::layout::arranged_element_collection::item_removed event.

Parameters
indexThe index of the item.
itemThe item removed.

Reimplemented from xtd::forms::layout::arranged_element_collection< control_ref >.


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