xtd 0.2.0
Loading...
Searching...
No Matches
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 {});
}
Stores an ordered pair of integers, which specify a height and width.
Definition size.hpp:31
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
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