Home

The Browse For Folder Dialog Box

 
 

Description

The Save and Open dialog boxes allow a user to save or open files only. Microsoft Windows provides a dialog box specially made so that a user can select a folder if an application needs one for any reason a programmers judges necessary. This dialog box appears as follows:

The Browse For Folder Dialog Box

When this dialog box comes up, it displays the Desktop folder as the parent and all the other folders can be located from it. To use it, the user can click one of the folders or drives and click OK. If the desired folder is not seen but is available, the user can expand the existing folders and drives, click the desired folder, and click OK. If the necessary folder is not available at all, the user can first select an existing folder or drive, click the Make New Folder button, type a name for the new folder, and click OK.

Besides the folders, the Browse For Folder dialog box also allows the user to navigate to folders or directories of the network.

Creating a Browse For Folder Dialog Box

The Browse For Folder dialog box is made available through the FolderBrowserDialog class that is derived from the CommonDialog class. To provide its functionality to your application, at design time, from the Toolbox, click FolderBrowserDialog FolderBrowserDialog and click the form.

To programmatically initiate this dialog box, you can declare a pointer to FolderBrowserDialog, use the new operator to allocate memory for it by calling its default constructor.

To display the Browse For Folder dialog box, call its ShowDialog() method. Here is an example:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
        }
    }
}

This would produce:

 

Home Copyright © 2007 FunctionX, Inc. Next