|
Open File Dialog Box Creation |
|
To provide file opening support, the .NET Framework provides the
OpenFileDialog class which is derived from the FileDialog class
that in fact provides most of its functionality. The easiest way to use it is to click the
OpenFileDialog button
from the Toolbox and click the form. You can click anywhere on the form because
the
OpenFileDialog object would not be seen at run time. After placing it on the form, you can use the
Properties window to configure it.
If you prefer to dynamically create an Open dialog box, declare a
variable of type OpenFileDialog and use the new operator to
allocate memory using its default constructor. Here is an example:
using System;
using System.Windows.Forms;
public class Exercise : Form
{
private OpenFileDialog ofd;
public Exercise()
{
InitializeComponent();
}
void InitializeComponent()
{
ofd = new OpenFileDialog();
}
}
public class Program
{
public static int Main()
{
Application.Run(new Exercise());
return 0;
}
}
|