//Создание Excel-документа private void button2_Click(object sender, EventArgs e) { button2.Enabled = false; Redactor redactor = new Redactor(); redactor.Excel_Create(Program.Redact.Name, LatinLtr, KirilLtr, Numbers, Space, Other); button2.Enabled = true; }
//Сохранение файла private void сохранитьToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show(file_path); switch (file_path != "") { case (true): if (File.Exists(file_path)) { FileInfo fileInfo = new FileInfo(file_path); switch (fileInfo.Extension) { case ("txt"): StreamWriter writer = new StreamWriter(file_path); writer.Write(Program.RedactorTextBox.Text); writer.Close(); break; case ("doc"): word.Application MSOW97 = new word.Application(); word.Document document97 = MSOW97.Documents.Add(Visible: true); word.Paragraph paragraph97 = document97.Paragraphs.Add(); paragraph97.Range.Text = Program.RedactorTextBox.Text; paragraph97.Range.Font.Name = Program.Font_Name; paragraph97.Range.Font.Size = Program.Font_Size; document97.SaveAs2(file_path, word.WdSaveFormat.wdFormatDocument97); document97.Close(); MSOW97.Quit(); break; case ("docx"): word.Application MSOW = new word.Application(); word.Document document = MSOW.Documents.Add(Visible: true); word.Paragraph paragraph = document.Paragraphs.Add(); paragraph.Range.Text = Program.RedactorTextBox.Text; paragraph.Range.Font.Name = Program.Font_Name; paragraph.Range.Font.Size = Program.Font_Size; document.SaveAs2(file_path, word.WdSaveFormat.wdFormatDocumentDefault); document.Close(); MSOW.Quit(); break; } } else { Redactor redactor = new Redactor(); redactor.save_dialog_execute(); } break; case (false): break; } }
//Сохранение по другому пути private void сохранитьКакToolStripMenuItem_Click(object sender, EventArgs e) { Redactor redactor = new Redactor(); redactor.saveFile.Filter = "Файл блокнота|*.txt|Microsoft Word 97-2003|*.doc|" + "Microsoft Word|*.docx"; redactor.save_dialog_execute(); }
//Добавление нового текстового окна при открытии формы 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); }