xtd 0.2.0
Loading...
Searching...
No Matches

◆ emplace_at()

template<typename control_t , typename ... 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/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/label>
using namespace xtd::drawing;
using namespace xtd::forms;
auto main() -> int {
auto button1_clicked = 0, button2_clicked = 0;
auto form1 = xtd::forms::form::create("Emplace example");
form1.controls().emplace<xtd::forms::button>(form1.controls().begin(), "Button 1", point{50, 50}).click += [&] {
form1.controls()["label1"].value().get().text(xtd::string::format("Button 1 clicked {} times", ++button1_clicked));
};
form1.controls().emplace_at<xtd::forms::button>(1, "Button 2", point {50, 100}, size {200, 75}).auto_repeat(true).click += [&] {
form1.controls()["label2"].value().get().text(xtd::string::format("Button 2 clicked {} times", ++button2_clicked));
};
form1.controls().emplace<xtd::forms::label>(form1.controls().end(), "Button 1 clicked 0 times", point {50, 200}, size {200, 23}, "label1");
form1.controls().emplace_back<xtd::forms::label>("Button 2 clicked 0 times", point {50, 230}, size {200, 23}, "label2");
}
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition point.h:54
Stores an ordered pair of integers, which specify a height and width.
Definition size.h:31
static void run()
Begins running a standard application message loop on the current thread, without a form.
Represents a Windows button control.
Definition button.h:49
control_t & emplace_back(args_t &&...args)
Creates and adds a control to the end.
Definition control.h:247
event< control, event_handler > click
Occurs when the xtd::forms::control is clicked.
Definition control.h:1482
virtual control_collection & controls() noexcept
Gets the collection of controls contained within the control.
static form create()
A factory to create an xtd::forms::form.
Represents a standard Windows label.
Definition label.h:38
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
size_t size
Represents a size of any object in bytes.
Definition size.h:23
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
emplace.cpp.