//Добавление нового текстового окна при открытии формы private void openFileDialog1_FileOk(object sender, CancelEventArgs e) { if (openFileDialog1.FileName != "") { file_path = openFileDialog1.FileName; Redactor redactor = new Redactor(); redactor.Form_Create(openFileDialog1.FileName, this); switch (openFileDialog1.FilterIndex) { case (1): if (File.Exists(openFileDialog1.FileName)) { StreamReader reader = new StreamReader(openFileDialog1.FileName); Program.RedactorTextBox.Text = reader.ReadToEnd(); reader.Close(); } break; case (2): word.Application application = new word.Application(); word.Document documents = application.Documents.Open(openFileDialog1.FileName); try { for (int i = 0; i < documents.Paragraphs.Count; ++i) { Program.RedactorTextBox.Font = new Font(documents.Paragraphs[i + 1].Range.Font.Name, documents.Paragraphs[i + 1].Range.Font.Size); Program.RedactorTextBox. AppendText(documents.Paragraphs[i + 1].Range.Text.ToString()); } } catch { } finally { documents.Close(); application.Quit(); } break; case (3): word.Application application1 = new word.Application(); word.Document documents1 = application1.Documents.Open(openFileDialog1.FileName); try { for (int i = 0; i < documents1.Paragraphs.Count; ++i) { Program.RedactorTextBox.Font = new Font(documents1.Paragraphs[i + 1].Range.Font.Name, documents1.Paragraphs[i + 1].Range.Font.Size); Program.RedactorTextBox.AppendText(documents1.Paragraphs[i + 1].Range.Text.ToString()); } } catch { } finally { documents1.Close(); application1.Quit(); } break; } } else { MessageBox.Show("Выберите файл", "Текстовый реадктор", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
//Создание окна текста private void новыйToolStripMenuItem_Click(object sender, EventArgs e) { Redactor redactor = new Redactor(); redactor.Form_Create("New_file", this); }