public static DialogResult OpenFile(RichTextDocument doc) { OpenFileDialog ofg = new OpenFileDialog() { CheckFileExists = true, CheckPathExists = true, ValidateNames = true, Title = "Open File - MDI Sample", Filter = "Text files (*.rtf)|*.rtf" }; if (ofg.ShowDialog() == DialogResult.OK) { doc.Location = ofg.FileName; try { TextReader textReader = new StreamReader(ofg.FileName, Encoding.Default, true); doc.Text = textReader.ReadToEnd(); textReader.Close(); return(DialogResult.OK); } catch (Exception exception) { MessageBox.Show("Ошибка открытия файла!/n" + exception.Message, "MDI Sample", MessageBoxButtons.OK, MessageBoxIcon.Error); } } return(DialogResult.Cancel); }
public RichTextEditor() { InitializeComponent(); document = new RichTextDocument(); document.TextChanged += new EventHandler(document_TextChanged); }
public static DialogResult OpenFile(RichTextDocument doc) { OpenFileDialog ofg = new OpenFileDialog() { CheckFileExists = true, CheckPathExists = true, ValidateNames = true, Title = "Open File - MDI Sample", Filter = "Text files (*.rtf)|*.rtf" }; if (ofg.ShowDialog() == DialogResult.OK) { doc.Location = ofg.FileName; try { TextReader textReader = new StreamReader(ofg.FileName, Encoding.Default, true); doc.Text = textReader.ReadToEnd(); textReader.Close(); return DialogResult.OK; } catch (Exception exception) { MessageBox.Show("Ошибка открытия файла!/n" + exception.Message, "MDI Sample", MessageBoxButtons.OK, MessageBoxIcon.Error); } } return DialogResult.Cancel; }
public static void SaveFile(RichTextDocument doc) { if (doc.Location != String.Empty) { Save(doc); } else { SaveFileAs(doc); } }
private static void Save(RichTextDocument doc) { try { TextWriter textWriter = new StreamWriter(doc.Location, false); textWriter.Write(doc.Text); textWriter.Close(); doc.isSaved = true; } catch { MessageBox.Show("Ошибка сохранения файла!", "MDI Sample", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void SaveFileAs(RichTextDocument doc) { SaveFileDialog sfd = new SaveFileDialog() { CheckPathExists = true, ValidateNames = true, AddExtension = true, Title = "Save File - MDI Sample", Filter = "Text files (*.rtf)|*.rtf" }; if (sfd.ShowDialog() == DialogResult.OK) { doc.Location = sfd.FileName; RichTextDocumentSaver.Save(doc); } }
public static void SaveFile(RichTextDocument doc) { if (doc.Location != String.Empty) Save(doc); else SaveFileAs(doc); }