openFileDialog1.ShowDialog() 對話匣 Filter: 文字檔案 (*.txt)|*.txt|所有檔 (*.*)|*.*
openFileDialog1.ShowDialog() DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) … if (openFileDialog1.ShowDialog() == DialogResult.OK){ } FileInfo fp = new FileInfo( "school.txt" ); openFileDialog1.FileName StreamReader sr = fp.OpenText(); // 開啟舊檔 “r” // fgets sr.Close(); string s = sr.ReadToEnd(); textBox1.Text = s; openFileDialog1.Filter= "文字檔案 (*.txt)|*.txt|所有檔 (*.*)|*.*";
saveFileDialog1.ShowDialog() DialogResult result = saveFileDialog1.ShowDialog(); if (result == DialogResult.OK) … if (saveFileDialog1.ShowDialog() == DialogResult.OK){ } FileInfo fp = new FileInfo( ); saveFileDialog1.FileName StreamWriter sw = fp.CreateText(); // 新增 “w” // fprintf sw.Close(); string s = textBox1.Text; sw.Write(s); string[] line = s.Split("\n"); // 把s變文字陣列line[] // char line[][] = {…};