xtd 0.2.0
open_file_box.cpp

demonstrates the use of xtd::forms::open_file_box file dialog.

Windows

macOS

Gnome

#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/message_box>
#include <xtd/forms/open_file_box>
using namespace xtd;
using namespace xtd::collections::generic;
using namespace xtd::forms;
class form1 : public form {
public:
form1() {
text("Open file box example");
client_size({400, 200});
controls().push_back_range({button_open_single_file, button_open_multiple_files});
button_open_single_file.parent(*this)
.location({10, 10})
.size({150, 35})
.text("Select single file")
.click += [this] {
string file_name;
auto res = open_file_box::show(file_name, *this, "Please select a file...", ".", "Text Files (*.txt)|*.txt|All Files (*.*)|*.*");
if (res == dialog_result::ok)
message_box::show(string::format("Selected file is:\n{}", file_name));
};
button_open_multiple_files.parent(*this)
.location({10, 45})
.size({150, 35})
.text("Select multiple files")
.click += [] {
auto file_names = list<string> {};
if (res == dialog_result::ok)
message_box::show(string::format("Selected files are:\n{}", string::join("\n", file_names)));
};
}
private:
button button_open_single_file;
button button_open_multiple_files;
};
auto main() -> int {
application::run(form1 {});
}
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:80
static void run()
Begins running a standard application message loop on the current thread, without a form.
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
static dialog_result show(const iwin32_window &owner)
Displays a message box in front of the specified window.
static xtd::forms::dialog_result show(xtd::string &file_name, const xtd::forms::iwin32_window &owner)
Displays a select file dialog box in front of a specified window.
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
@ show_hidden_files
Whether hidden files are displayed in the file dialog box.
Definition open_file_box_options.hpp:36
@ check_file_exists
Whether the dialog box displays a warning if the user specifies a file name that does not exist.
Definition open_file_box_options.hpp:26
@ ok
The dialog box return value is OK (usually sent from a button labeled OK).
Definition dialog_result.hpp:47
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
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