發(fā)布時間:2017-09-15 14:08 作者:獨孤劍 閱讀:1207
using System; using System.Windows.Forms; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } /// <summary> /// 選擇文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Multiselect = true; openFileDialog1.Title = "請選擇文件"; openFileDialog1.Filter = "所有文件(*.*)|*.*"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { string filename = openFileDialog1.FileName; MessageBox.Show("已選擇文件:" + filename, "選擇文件提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } /// <summary> /// 選擇文件夾、路徑 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog(); folderBrowserDialog1.Description = "請選擇文件路徑"; if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { string path = folderBrowserDialog1.SelectedPath; MessageBox.Show("已選擇文件夾:" + path, "選擇文件夾提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } /// <summary> /// 打開目錄 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("Explorer.exe", "C:\\Windows"); } } }
微信打賞, 微信掃一掃
支付寶打賞, 支付寶掃一掃
如果文章對您有幫助,歡迎給作者打賞