logo search
Учебник_ПОА

To display the folder browser dialog box

  1. On the File menu, click New Project.

The New Project dialog box appears.

  1. Click Windows Forms Application and then click OK.

  2. Add a Label control to the form, and use the default name, Label1.

  3. Add a Button control to the form, and change the following properties in the Properties window:

Property

Value

Name

folderPath

Text

Path

  1. Drag a FolderBrowserDialog component from the Dialogs tab of the Toolbox to the form.

folderBrowserDialog1 appears in the component tray.

  1. Double-click the button to create the default event handler in the Code Editor.

  2. In the folderPath_Click event handler, add the following code to display the folder browser dialog box and display the selected path in the label.

    if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)

    {

    this.label1.Text = folderBrowserDialog1.SelectedPath;

    }

  3. Press F5 to run the code.

  4. When the form appears, click Path, click a folder in the list, and then click OK.

  5. Verify that the selected path appears in the label.

  6. Close the application.