-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOpenFileDialog.cs
More file actions
36 lines (31 loc) · 1.22 KB
/
OpenFileDialog.cs
File metadata and controls
36 lines (31 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Windows.Forms;
namespace FolderBrowserDialogExample {
class Form1 : Form {
// The main entry point for the application.
[STAThread]
public static void Main() {
Application.EnableVisualStyles();
Application.Run(new Form1());
}
public Form1() {
button.Text = "Open...";
button.Location = new System.Drawing.Point(10, 10);
button.Click += delegate(object sender, EventArgs e) {
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
System.Diagnostics.Debug.WriteLine(string.Format("dialog = {0}", openFileDialog));
if (openFileDialog.ShowDialog() == DialogResult.OK)
label.Text = string.Format("File = {0}", openFileDialog.FileName);
};
label.Text = "Path = ";
label.Location = new System.Drawing.Point(10, 40);
label.Width = 340;
Text = "OpenFileDialog example";
Controls.AddRange(new Control[] { button, label});
}
private Button button = new Button();
private Label label = new Label();
}
}