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...
	}
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.