xtd 0.2.0
image_list.cpp

demonstrates the use of xtd::forms::image_list component.

Windows

macOS

Gnome

#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/button_images>
#include <xtd/forms/form>
#include <xtd/forms/open_file_dialog>
#include <xtd/forms/picture_box>
#include <xtd/drawing/system_colors>
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::forms;
namespace example {
class form1 : public form {
public:
form1() {
text("Image list example");
client_size({300, 250});
controls().push_back_range({picture, button_previous, button_next});
pictures.image_size({128, 128});
picture.back_color(system_colors::window());
picture.border_style(forms::border_style::fixed_3d);
picture.bounds({75, 25, 150, 150});
picture.click += [&] {
load_images();
};
button_previous.auto_repeat(true);
button_previous.image(button_images::previous());
button_previous.location({75, 200});
button_previous.enabled(false);
button_previous.click += [&] {
if (current_image_index > 0) picture.image(pictures.images()[--current_image_index]);
button_previous.enabled(current_image_index > 0);
button_next.enabled(current_image_index < pictures.images().size() - 1);
};
button_next.auto_repeat(true);
button_next.image(button_images::next());
button_next.location({150, 200});
button_next.enabled(false);
button_next.click += [&] {
if (current_image_index < pictures.images().size()) picture.image(pictures.images()[++current_image_index]);
button_previous.enabled(current_image_index > 0);
button_next.enabled(current_image_index < pictures.images().size() - 1);
};
show();
load_images();
}
private:
void load_images() {
auto dialog = open_file_dialog {};
dialog.multiselect(true);
dialog.filter("All Image Files|*.bmp;*.gif;*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.xpm|Bitmap Files|*.bmp|Gif Files|*.gif|Jpeg Files|*.jpg;*.jpeg|Png Files|*.png|Tiff Files|*.tif;*.tiff|xpm Files|*.xpm");
if (dialog.show_dialog() == dialog_result::ok) {
pictures.images().clear();
for (auto file : dialog.file_names())
pictures.images().push_back(drawing::image::from_file(file));
current_image_index = 0;
picture.image(pictures.images()[current_image_index]);
button_previous.enabled(current_image_index > 0);
button_next.enabled(current_image_index < pictures.images().size() - 1);
}
}
size_t current_image_index = 0;
image_list pictures;
picture_box picture;
button button_previous;
button button_next;
};
}
auto main() -> int {
application::run(example::form1 {});
}
static image from_file(const xtd::string &filename)
Creates an image from the specified file.
static xtd::drawing::color window()
Gets a xtd::drawing::color structure that is the color of the background in the client area of a wind...
static void run()
Begins running a standard application message loop on the current thread, without a form.
static xtd::drawing::image next()
Next image object.
Definition button_images.hpp:98
static xtd::drawing::image previous()
Previous image object.
Definition button_images.hpp:132
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
Provides methods to manage a collection of xtd::drawing::image objects. This class cannot be inherite...
Definition image_list.hpp:30
Displays a standard dialog box that prompts the user to open a file. This class cannot be inherited.
Definition open_file_dialog.hpp:30
virtual bool multiselect() const noexcept
Gets a value indicating whether the dialog box allows multiple files to be selected.
Represents a standard Windows picture box.
Definition picture_box.hpp:34
@ center_image
The image is displayed in the center if the picture_box is larger than the image. If the image is lar...
Definition picture_box_size_mode.hpp:30
@ ok
The dialog box return value is OK (usually sent from a button labeled OK).
Definition dialog_result.hpp:47
@ fixed_3d
A three-dimensional border. Same as xtd::forms::border_style::inset.
Definition border_style.hpp:58
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