O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

6.7. Exploring the File Dialog

Nobody really wants to type in a file name, let alone a file name and path. What users want is a directory tree dialog window to pop up that they can navigate and select from. The first step, as always, is to drag the control onto the form. Unlike the other controls so far, OpenFileDialog is not a visible control. It does not display in the form. Rather we need to associate it with a visible control. The usual suspect is an Open menu item.

When the user clicks the menu item, we need to respond by invoking the openFileDialog1 object's ShowDialog() member function. The menu item event handler looks like this:

 private void menuItem2_Click(object sender, System.EventArgs e) { Text = "Open Menu Item Clicked"; openFileDialog1.ShowDialog(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required