using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace ComponentSurveySample { public partial class CommonDialogsForm : Form { public CommonDialogsForm() { InitializeComponent(); } private void openFileDialogButton_Click(object sender, EventArgs e) { // Set initial file name this.openFileDialog.FileName = this.fileNameTextBox.Text; // Ask the user to pick a file to open if( this.openFileDialog.ShowDialog() == DialogResult.OK ) { // Pull out the user's choice this.fileNameTextBox.Text = this.openFileDialog.FileName; } } private void saveFileDialogButton_Click(object sender, EventArgs e) { // Set initial file name this.saveFileDialog.FileName = this.fileNameTextBox.Text; // Ask the user to pick/create a file to save to if( this.saveFileDialog.ShowDialog() == DialogResult.OK ) { // Pull out the user's choice this.fileNameTextBox.Text = this.saveFileDialog.FileName; } } private void folderBrowserDialogButton_Click(object sender, EventArgs e) { // Provide detailed instructions to the user this.folderBrowserDialog.Description = "Select the folder that contains the desired files."; // Set the initial folder path this.folderBrowserDialog.SelectedPath = this.folderPathTextBox.Text; // Ask the user to pick a folder if( this.folderBrowserDialog.ShowDialog() == DialogResult.OK ) { // Pull out the user's choice this.folderPathTextBox.Text = this.folderBrowserDialog.SelectedPath; } } private void colorDialogButton_Click(object sender, EventArgs e) { // Set initial color this.colorDialog.Color = this.BackColor; // Ask the user to pick a color if( this.colorDialog.ShowDialog() == DialogResult.OK ) { // Pull out the user's choice this.BackColor = this.colorDialog.Color; } } private void fontDialogButton_Click(object sender, EventArgs e) { // Set initial font this.fontDialog.Font = this.Font; // Ask the user to pick a font if( this.fontDialog.ShowDialog() == DialogResult.OK ) { // Pull out the user's choice this.Font = this.fontDialog.Font; } } } }