<pre lang="c#"> public partial class frmChild2 : Form { public frmChild2() { InitializeComponent(); } public frmChild2 ( string fileName ) : this() { Savefile(fileName); } private void Savefile ( string fileName ) { string strExt; strExt = System.IO.Path.GetExtension(fileName); strExt = strExt.ToUpper(); if (strExt == ".RTF") { richTextBox1.LoadFile(fileName, RichTextBoxStreamType.RichText); } else { System.IO.StreamReader txtReader; txtReader = new System.IO.StreamReader(fileName); richTextBox1.Text = txtReader.ReadToEnd(); txtReader.Close(); txtReader = null; richTextBox1.SelectionStart = 0; richTextBox1.SelectionLength = 30; } richTextBox1.Modified = true; this.Text = "Unit 9 Editor: " + fileName; } private void btnSave_Click(object sender, EventArgs e) { SaveFileDialog savefileDialog = new SaveFileDialog(); savefileDialog.DefaultExt = "txt"; savefileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); savefileDialog.Filter = "Text Files (*.txt)|*.txt|Html Files (*.htm)|*.htm|Rich Text Files (*.rtf)|*.rtf|All Files (*.*)|*.*"; savefileDialog.FilterIndex = 1; savefileDialog.FileName = string.Empty; if (savefileDialog.ShowDialog(this) == DialogResult.OK && savefileDialog.FileName != String.Empty) { Form frmChild = new frmChild2 (savefileDialog.FileName); frmChild = this; frmChild.Show(); } else { MessageBox.Show("Save File request cancelled by user.", "Cancelled"); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)