See ‘Forms’ for details of creating forms to be bespoke dialog boxes

Select A Folder Dialog Box


	FolderBrowserDialog ^SelectFolderDialog = gcnew FolderBrowserDialog();

	//Setup dialog box
	SelectFolderDialog->Description = "Select the central network directory where files are stored";
	SelectFolderDialog->ShowNewFolderButton = true;
	SelectFolderDialog->RootFolder = System::Environment::SpecialFolder::Desktop;
	try
	{
		SelectFolderDialog->SelectedPath = txtGeneralFileStoreDirectory->Text;
	}
	catch (Exception ^e)
	{
		SelectFolderDialog->SelectedPath = "C:\\";
	}
	//Display dialog box
	if (SelectFolderDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK)
	{

Open File Dialog Box


	//----- OPEN FILE DIALOG BOX -----
	OpenFileDialog ^SelectFileDialog = gcnew OpenFileDialog();

	SelectFileDialog->Filter = "Libra Config Files (*.lib)|*.lib";	//"txt files (*.txt)|*.txt|All files (*.*)|*.*"
	SelectFileDialog->FilterIndex = 1;				//(First = 1, not 0)
	try
	{
		SelectFileDialog->InitialDirectory = OurLastFileDirectory;
	}
	catch (Exception ^e)
	{
		SelectFileDialog->InitialDirectory = Environment::GetFolderPath(Environment::SpecialFolder::MyDocuments);
	}
	//Display dialog box
	if (SelectFileDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK)
	{
		String ^FileName = SelectFileDialog->FileName;
		//Open the file...

	}

Save File Dialog Box


	//----- SAVE FILE DIALOG BOX -----
	SaveFileDialog ^SelectFileDialog = gcnew SaveFileDialog();

	SelectFileDialog->Filter = "Libra Config Files (*.lib)|*.lib";	//"txt files (*.txt)|*.txt|All files (*.*)|*.*"
	SelectFileDialog->FilterIndex = 1;				//(First = 1, not 0)
	try
	{
		SelectFileDialog->InitialDirectory = LastFileDirectory;
	}
	catch (Exception ^e)
	{
		SelectFileDialog->InitialDirectory = Environment::GetFolderPath(Environment::SpecialFolder::MyDocuments);
	}
	//Display dialog box
	if (SelectFileDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK) 	//This ensures correct filename extension is used
	{
		//----- SAVE THE FILE -----
		String ^FileName = SelectFileDialog->FileName;
		//Save the file...
	}
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published.