xtd 0.2.0
Loading...
Searching...
No Matches
xtd::forms::open_file_dialog Class Referencefinal
Inheritance diagram for xtd::forms::open_file_dialog:
xtd::forms::file_dialog xtd::forms::common_dialog xtd::forms::component xtd::object

Definition

Displays a standard dialog box that prompts the user to open a file. This class cannot be inherited.

Header
#include <xtd/forms/open_file_dialog>
Namespace
xtd::forms
Library
xtd.forms
Appearance
Windows macOS Gnome
Light  
 
 
 
 
 
Dark  
 
 
 
 
 
Examples
The following code example demonstrates the use of open_file_dialog dialog.
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/label>
#include <xtd/forms/open_file_dialog>
using namespace xtd;
using namespace xtd::forms;
class form1 : public form {
public:
form1() {
text("Open file dialog example");
controls().push_back(button1);
auto_scroll(true);
button1.location({10, 10});
button1.text("Open...");
button1.click += [&] {
auto dialog = open_file_dialog {};
dialog.initial_directory(file_name.empty() ? environment::get_folder_path(environment::special_folder::desktop) : io::path::get_directory_name(file_name));
dialog.file_name(io::path::get_file_name(file_name));
dialog.filter("Text Files (*.txt)|*.txt|All Files (*.*)|*.*");
if (dialog.show_sheet_dialog(*this) == forms::dialog_result::ok) {
file_name = dialog.file_name();
label1.text(ustring::format("File = {}", file_name));
}
};
label1.parent(*this);
label1.text("File = ");
label1.auto_size(true);
label1.location({10, 50});
}
private:
label label1;
ustring file_name;
};
auto main()->int {
application::run(form1 {});
}
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:47
virtual const xtd::ustring & initial_directory() const noexcept
Gets the initial directory displayed by the file dialog box.
Represents a window or dialog box that makes up an application's user interface.
Definition form.h:52
Represents a standard Windows label.
Definition label.h:36
Displays a standard dialog box that prompts the user to open a file. This class cannot be inherited.
Definition open_file_dialog.h:28
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
@ path
The xtd::uri::local_path data.
@ button1
The first button on the message box is the default button.
@ text
The xtd::forms::status_bar_panel displays text in the standard font.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.h:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Examples
image_list.cpp, open_file_dialog.cpp, and painting.cpp.

Public Constructors

 open_file_dialog ()=default
 Initializes a new instance of the open_file_dialog class.
 

Public Properties

std::ifstream open_file () const noexcept
 Opens the file with read only permission selected by the user.
 
virtual bool multiselect () const noexcept
 Gets a value indicating whether the dialog box allows multiple files to be selected.
 
virtual open_file_dialogmultiselect (bool value)
 Sets a value indicating whether the dialog box allows multiple files to be selected.
 

Additional Inherited Members

- Public Attributes inherited from xtd::forms::common_dialog
event< common_dialog, help_event_handlerhelp_request
 Occurs when the user clicks the Help button on a common dialog box.
 
event< common_dialog, dialog_closed_event_handlerdialog_closed
 Occurs when the user close a common dialog box with dialog close button or other dialog buttons.
 
- Public Member Functions inherited from xtd::forms::file_dialog
 file_dialog ()
 Initializes a new instance of the common_dialog class.
 
virtual bool add_extension () const noexcept
 Gets a value indicating whether the dialog box automatically adds an extension to a file name if the user omits the extension.
 
virtual file_dialogadd_extension (bool value)
 Sets a value indicating whether the dialog box automatically adds an extension to a file name if the user omits the extension.
 
virtual bool auto_upgrade_enabled () const noexcept
 Gets a value indicating whether this file_dialog instance should automatically upgrade appearance and behavior when running on Windows Vista.
 
virtual file_dialogauto_upgrade_enabled (bool value)
 Sets a value indicating whether this file_dialog instance should automatically upgrade appearance and behavior when running on Windows Vista.
 
virtual bool check_file_exists () const noexcept
 Gets a value indicating whether the dialog box displays a warning if the user specifies a file name that does not exist.
 
virtual file_dialogcheck_file_exists (bool value)
 Sets a value indicating whether the dialog box displays a warning if the user specifies a file name that does not exist.
 
virtual bool check_path_exists () const noexcept
 Gets a value indicating whether the dialog box displays a warning if the user specifies a path that does not exist.
 
virtual file_dialogcheck_path_exists (bool value)
 Sets a value indicating whether the dialog box displays a warning if the user specifies a path that does not exist.
 
virtual const xtd::ustringdefault_ext () const noexcept
 Gets the default file name extension.
 
virtual file_dialogdefault_ext (const xtd::ustring &value)
 Sets the default file name extension.
 
virtual bool dereference_link () const noexcept
 Gets a value indicating whether the dialog box returns the location of the file referenced by the shortcut or whether it returns the location of the shortcut (.lnk).
 
virtual file_dialogdereference_link (bool value)
 Sets a value indicating whether the dialog box returns the location of the file referenced by the shortcut or whether it returns the location of the shortcut (.lnk).
 
virtual const xtd::ustringfile_name () const noexcept
 Gets a string containing the file name selected in the file dialog box.
 
virtual file_dialogfile_name (const xtd::ustring &value)
 Sets a string containing the file name selected in the file dialog box.
 
virtual const std::vector< xtd::ustringfile_names () const noexcept
 Gets the file names of all selected files in the dialog box.
 
virtual const xtd::ustringfilter () const noexcept
 Gets the current file name filter string, which determines the choices that appear in the "Save as file type" or "Files of type" box in the dialog box.
 
virtual file_dialogfilter (const xtd::ustring &value)
 Sets the current file name filter string, which determines the choices that appear in the "Save as file type" or "Files of type" box in the dialog box.
 
virtual size_t filter_index () const noexcept
 Gets the index of the filter currently selected in the file dialog box.
 
virtual file_dialogfilter_index (size_t value)
 Sets the index of the filter currently selected in the file dialog box.
 
virtual const xtd::ustringinitial_directory () const noexcept
 Gets the initial directory displayed by the file dialog box.
 
virtual file_dialoginitial_directory (const xtd::ustring &value)
 Sets the initial directory displayed by the file dialog box.
 
size_t options () const noexcept
 Gets values to initialize the file_dialog.
 
virtual bool restore_directory () const noexcept
 Gets a value indicating whether the dialog box restores the directory to the previously selected directory before closing.
 
virtual file_dialogrestore_directory (bool value)
 Sets a value indicating whether the dialog box restores the directory to the previously selected directory before closing.
 
virtual bool show_help () const noexcept
 Gets a value indicating whether the Help button is displayed in the file dialog box.
 
virtual file_dialogshow_help (bool value)
 Sets a value indicating whether the Help button is displayed in the file dialog box.
 
virtual bool show_hidden_files () const noexcept
 Gets a value indicating whether hidden files are displayed in the file dialog box.
 
virtual file_dialogshow_hidden_files (bool value)
 Sets a value indicating whether hidden files are displayed in the file dialog box.
 
virtual bool show_preview () const noexcept
 Gets a value indicating whether preview file is displayed in the file dialog box.
 
virtual file_dialogshow_preview (bool value)
 Sets a value indicating whether preview file is displayed in the file dialog box.
 
virtual bool support_multi_dotted_extensions () const noexcept
 Gets whether the dialog box supports displaying and saving files that have multiple file name extensions.Gets or sets whether the dialog box supports displaying and saving files that have multiple file name extensions.
 
virtual file_dialogsupport_multi_dotted_extensions (bool value)
 Sets whether the dialog box supports displaying and saving files that have multiple file name extensions.Gets or sets whether the dialog box supports displaying and saving files that have multiple file name extensions.
 
virtual const xtd::ustringtitle () const noexcept
 Gets the file dialog box title.
 
virtual file_dialogtitle (const xtd::ustring &value)
 Sets the file dialog box title.
 
virtual bool validate_names () const noexcept
 Gets a value indicating whether the dialog box accepts only valid file names.
 
virtual file_dialogvalidate_names (bool value)
 Gets a value indicating whether the dialog box accepts only valid file names.
 
void reset () noexcept override
 Resets all properties to their default values.
 
xtd::ustring to_string () const noexcept override
 Provides a string version of this object.
 
- Public Member Functions inherited from xtd::forms::common_dialog
 common_dialog ()
 Initializes a new instance of the common_dialog class.
 
xtd::forms::dialog_result dialog_result () const noexcept
 Gets async dialog_result result after dialog box is closing.
 
std::any tag () const noexcept
 Gets an object that contains data about the control.
 
common_dialogtag (const std::any &tag)
 Sets an object that contains data about the control.
 
xtd::forms::dialog_result show_dialog ()
 Runs a common dialog box with a default owner.
 
xtd::forms::dialog_result show_dialog (const iwin32_window &owner)
 Runs a common dialog box with the specified owner.
 
void show_sheet (const iwin32_window &owner)
 Runs a common dialog box with the specified owner.
 
xtd::forms::dialog_result show_sheet_dialog (const iwin32_window &owner)
 Runs a common dialog box with the specified owner.
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const noexcept
 Creates a shallow copy of the current object.
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 
- Protected Member Functions inherited from xtd::forms::file_dialog
bool run_dialog (intptr hwnd_owner) override
 Runs file dialog box.
 
void run_sheet (intptr hwnd_owner) override
 Runs file dialog box in sheet mode.
 
- Protected Member Functions inherited from xtd::forms::common_dialog
virtual void on_dialog_closed (const dialog_closed_event_args &e)
 Raises the common_dialog::dialog_close event.
 
virtual void on_help_request (help_event_args &e)
 Raises the common_dialog::help_request event.
 
void set_dialog_result (xtd::forms::dialog_result value)
 Sets async dialog_result result after dialog box is closing.
 
- Protected Member Functions inherited from xtd::forms::component
 component ()
 Initialises a new instance of the component class.
 
virtual bool can_raise_events () const noexcept
 Gets a value indicating whether the component can raise an event.
 
bool design_mode () const noexcept
 Gets a value that indicates whether the component is currently in design mode.
 

Constructor & Destructor Documentation

◆ open_file_dialog()

xtd::forms::open_file_dialog::open_file_dialog ( )
default

Initializes a new instance of the open_file_dialog class.

Member Function Documentation

◆ multiselect() [1/2]

virtual bool xtd::forms::open_file_dialog::multiselect ( ) const
virtualnoexcept

Gets a value indicating whether the dialog box allows multiple files to be selected.

Returns
true if the dialog box allows multiple files to be selected together or concurrently; otherwise, false. The default value is false.
Remarks
Use the file_names property to access the full list of selected file names.
Examples
image_list.cpp.

◆ multiselect() [2/2]

virtual open_file_dialog & xtd::forms::open_file_dialog::multiselect ( bool  value)
virtual

Sets a value indicating whether the dialog box allows multiple files to be selected.

Parameters
valuetrue if the dialog box allows multiple files to be selected together or concurrently; otherwise, false. The default value is false.
Returns
Current open_file_dialog.
Remarks
Use the file_names property to access the full list of selected file names.

◆ open_file()

std::ifstream xtd::forms::open_file_dialog::open_file ( ) const
noexcept

Opens the file with read only permission selected by the user.

Returns
The read only file selected by the user.

The documentation for this class was generated from the following file: