xtd 0.2.0
form_resize.cpp

Shows how to set minimum size, set maximum size, move and resize a form.

Windows

macOS

Gnome

#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/button_images>
#include <xtd/forms/form>
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::forms;
class form1 : public form {
public:
form1() {
client_size({220, 115});
maximum_client_size(client_size() + drawing::size {300, 300});
minimum_client_size(client_size());
controls().push_back_range({up_button, left_button, right_button, down_button, shrink_button, grow_button});
text("Form resize example");
key_down += [&](auto sender, auto e) {
if (e.key_code() == keys::right) left(left() + 10);
else if (e.key_code() == keys::left) left(left() - 10);
else if (e.key_code() == keys::down) top(top() + 10);
else if (e.key_code() == keys::up) top(top() - 10);
};
key_press += [&](auto sender, auto e) {
if (e.key_char() == '+') size(size() + drawing::size {10, 10});
else if (e.key_char() == '-') size(size() - drawing::size {10, 10});
};
up_button.auto_repeat(true);
up_button.bounds({45, 10, 25, 25});
up_button.image(button_images::from_name("go-up"));
up_button.click += [&] {
top(top() - 10);
};
left_button.auto_repeat(true);
left_button.bounds({10, 45, 25, 25});
left_button.image(button_images::from_name("go-previous"));
left_button.click += [&] {
left(left() - 10);
};
right_button.auto_repeat(true);
right_button.bounds({80, 45, 25, 25});
right_button.image(button_images::from_name("go-next"));
right_button.click += [&] {
left(left() + 10);
};
down_button.auto_repeat(true);
down_button.bounds({45, 80, 25, 25});
down_button.image(button_images::from_name("go-down"));
down_button.click += [&] {
top(top() + 10);
};
shrink_button.auto_repeat(true);
shrink_button.bounds({150, 45, 25, 25});
shrink_button.image(button_images::from_name("zoom-out"));
shrink_button.click += [&] {
size(size() - drawing::size {10, 10});
};
grow_button.auto_repeat(true);
grow_button.bounds({185, 45, 25, 25});
grow_button.image(button_images::from_name("zoom-in"));
grow_button.click += [&] {
size(size() + drawing::size {10, 10});
};
}
private:
button up_button;
button left_button;
button right_button;
button down_button;
button grow_button;
button shrink_button;
};
auto main() -> int {
application::run(form1 {});
}
static void run()
Begins running a standard application message loop on the current thread, without a form.
static xtd::drawing::image from_name(const xtd::string &name)
Gets image object with specified name.
Definition button_images.hpp:193
Represents a Windows button control.
Definition button.hpp:49
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
@ e
The E key.
Definition console_key.hpp:96
@ up
The UP key.
Definition keys.hpp:157
@ down
The DOWN key.
Definition keys.hpp:161
@ right
The RIGHT key.
Definition keys.hpp:159
@ left
The LEFT key.
Definition keys.hpp:155
@ left
Bind control edges to the left of its container.
Definition anchor_styles.hpp:27
@ top
Bind control edges to the top of its container.
Definition anchor_styles.hpp:23
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
Stores an ordered pair of integers, which specify a height and width.
Definition size.hpp:31