openFileDialog/saveFileDialog/folderBrowserDialog三个控件的应用(winform程序简单)

如上图所示布局,打开文件按钮将把打开的文件内容在textbox中显示

打开文件按钮代码:

<textarea cols="50" rows="15" name="code" class="c-sharp"> if (openFileDialog1.ShowDialog() == DialogResult.OK) { string filename = openFileDialog1.FileName; string[] lines = File.ReadAllLines(filename); foreach (var line in lines) { string[] strs = line.Split('|'); txtboxstring.AppendText(string.Format("{0}的成绩为:{1}", strs[0], strs[1]) + "/n"); } } </textarea> 

另存为按钮代码:

<textarea cols="50" rows="15" name="code" class="c-sharp"> if (saveFileDialog1.ShowDialog() == DialogResult.OK) { string filename = saveFileDialog1.FileName; File.WriteAllText(filename, txtboxstring.Text); } </textarea> 

浏览文件夹按钮代码:

<textarea cols="50" rows="15" name="code" class="c-sharp"> if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { string filename = folderBrowserDialog1.SelectedPath; txtboxstring.Text = filename; } </textarea> 

你可能感兴趣的:(openFileDialog/saveFileDialog/folderBrowserDialog三个控件的应用(winform程序简单))