{"id":546,"date":"2011-01-06T20:34:44","date_gmt":"2011-01-06T20:34:44","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=546"},"modified":"2022-02-17T06:24:04","modified_gmt":"2022-02-17T06:24:04","slug":"dialog-boxes-general","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/dialog-boxes\/dialog-boxes-general","title":{"rendered":"Dialog Boxes General"},"content":{"rendered":"<p>See &#8216;Forms&#8217; for details of creating forms to be bespoke dialog boxes<\/p>\n<h4>Select A Folder Dialog Box<\/h4>\n<pre><code>\r\n\tFolderBrowserDialog ^SelectFolderDialog = gcnew FolderBrowserDialog();\r\n\r\n\t\/\/Setup dialog box\r\n\tSelectFolderDialog-&gt;Description = \"Select the central network directory where files are stored\";\r\n\tSelectFolderDialog-&gt;ShowNewFolderButton = true;\r\n\tSelectFolderDialog-&gt;RootFolder = System::Environment::SpecialFolder::Desktop;\r\n\ttry\r\n\t{\r\n\t\tSelectFolderDialog-&gt;SelectedPath = txtGeneralFileStoreDirectory-&gt;Text;\r\n\t}\r\n\tcatch (Exception ^e)\r\n\t{\r\n\t\tSelectFolderDialog-&gt;SelectedPath = \"C:\\\\\";\r\n\t}\r\n\t\/\/Display dialog box\r\n\tif (SelectFolderDialog-&gt;ShowDialog() == System::Windows::Forms::DialogResult::OK)\r\n\t{\r\n<\/code><\/pre>\n<h4>Open File Dialog Box<\/h4>\n<pre><code>\r\n\t\/\/----- OPEN FILE DIALOG BOX -----\r\n\tOpenFileDialog ^SelectFileDialog = gcnew OpenFileDialog();\r\n\r\n\tSelectFileDialog-&gt;Filter = \"Libra Config Files (*.lib)|*.lib\";\t\/\/\"txt files (*.txt)|*.txt|All files (*.*)|*.*\"\r\n\tSelectFileDialog-&gt;FilterIndex = 1;\t\t\t\t\/\/(First = 1, not 0)\r\n\ttry\r\n\t{\r\n\t\tSelectFileDialog-&gt;InitialDirectory = OurLastFileDirectory;\r\n\t}\r\n\tcatch (Exception ^e)\r\n\t{\r\n\t\tSelectFileDialog-&gt;InitialDirectory = Environment::GetFolderPath(Environment::SpecialFolder::MyDocuments);\r\n\t}\r\n\t\/\/Display dialog box\r\n\tif (SelectFileDialog-&gt;ShowDialog() == System::Windows::Forms::DialogResult::OK)\r\n\t{\r\n\t\tString ^FileName = SelectFileDialog-&gt;FileName;\r\n\t\t\/\/Open the file...\r\n\r\n\t}\r\n<\/code><\/pre>\n<h4>Save File Dialog Box<\/h4>\n<pre><code>\r\n\t\/\/----- SAVE FILE DIALOG BOX -----\r\n\tSaveFileDialog ^SelectFileDialog = gcnew SaveFileDialog();\r\n\r\n\tSelectFileDialog-&gt;Filter = \"Libra Config Files (*.lib)|*.lib\";\t\/\/\"txt files (*.txt)|*.txt|All files (*.*)|*.*\"\r\n\tSelectFileDialog-&gt;FilterIndex = 1;\t\t\t\t\/\/(First = 1, not 0)\r\n\ttry\r\n\t{\r\n\t\tSelectFileDialog-&gt;InitialDirectory = LastFileDirectory;\r\n\t}\r\n\tcatch (Exception ^e)\r\n\t{\r\n\t\tSelectFileDialog-&gt;InitialDirectory = Environment::GetFolderPath(Environment::SpecialFolder::MyDocuments);\r\n\t}\r\n\t\/\/Display dialog box\r\n\tif (SelectFileDialog-&gt;ShowDialog() == System::Windows::Forms::DialogResult::OK) \t\/\/This ensures correct filename extension is used\r\n\t{\r\n\t\t\/\/----- SAVE THE FILE -----\r\n\t\tString ^FileName = SelectFileDialog-&gt;FileName;\r\n\t\t\/\/Save the file...\r\n\t}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>See &#8216;Forms&#8217; for details of creating forms to be bespoke dialog boxes Select A Folder Dialog Box FolderBrowserDialog ^SelectFolderDialog = gcnew FolderBrowserDialog(); \/\/Setup dialog box SelectFolderDialog-&gt;Description = &#8220;Select the central network directory where files are stored&#8221;; SelectFolderDialog-&gt;ShowNewFolderButton = true; SelectFolderDialog-&gt;RootFolder = System::Environment::SpecialFolder::Desktop; try { SelectFolderDialog-&gt;SelectedPath = txtGeneralFileStoreDirectory-&gt;Text; } catch (Exception ^e) { SelectFolderDialog-&gt;SelectedPath = &#8220;C:\\\\&#8221;; [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[],"class_list":["post-546","post","type-post","status-publish","format-standard","hentry","category-dialog-boxes"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/546","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/comments?post=546"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/546\/revisions"}],"predecessor-version":[{"id":1056,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/546\/revisions\/1056"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}