int findCutLength = 0; // На сколько символов обрезаем текст для поиска public SearchForm() { InitializeComponent(); tbFind.TextChanged += (s, a) => { findCutLength = 0; }; tbReplace.TextChanged += (s, a) => { findCutLength = 0; }; cbReg.CheckStateChanged += (s, a) => { findCutLength = 0; }; btFind.Click += (s, a) => { if (this.Owner is MainForm main) { if (cbReg.CheckState == CheckState.Checked) { TextWork.FindTextBox(ref main.note, findText: tbFind.Text, findCutLength: ref findCutLength, register: true); } else { TextWork.FindTextBox(ref main.note, findText: tbFind.Text, findCutLength: ref findCutLength, register: false); } } }; btReplace.Click += (s, a) => { if (this.Owner is MainForm main) { if (cbReg.CheckState == CheckState.Checked) { TextWork.ReplaceTextBox(ref main.note, findText: tbFind.Text, replaceText: tbReplace.Text, findCutLength: ref findCutLength, register: true); } else { TextWork.ReplaceTextBox(ref main.note, findText: tbFind.Text, replaceText: tbReplace.Text, findCutLength: ref findCutLength, register: false); } } }; btReplaceAll.Click += (s, a) => { if (this.Owner is MainForm main) { if (cbReg.CheckState == CheckState.Checked) { TextWork.ReplaceAllTextBox(ref main.note, findText: tbFind.Text, replaceText: tbReplace.Text, register: true); } else { TextWork.ReplaceAllTextBox(ref main.note, findText: tbFind.Text, replaceText: tbReplace.Text, register: false); } } }; btCancel.Click += (s, a) => { this.Close(); }; }
public MainForm() { InitializeComponent(); this.Text = Properties.Settings.Default.newDocName + " - " + Properties.Settings.Default.programmName; note.TextChanged += (s, a) => { tbChange = true; // Индикатор изменения текста TextWork.EditEnableds(ref note, ref copy, ref cut, ref delete, ref findReplace, ref go); TextWork.StatusAnalize(ref note, ref statusLinesCount, ref statusWordsCount, ref statusCharSpaceCount, ref statusCharCount); }; // ----------------------- Меню File ----------------------------------------------- newFile.Click += (s, a) => { if (tbChange == true) { DialogResult message = MessageBox.Show("Сохранить текущий документ перед созданием нового?", "Создание документа", MessageBoxButtons.YesNoCancel); if (message == DialogResult.Yes) { if (docPath != "") { FileWork.SaveFile(ref note, ref tbChange, ref docPath); FileWork.CreateFile(ref note, ref tbChange, ref docPath); } else if (docPath == "") { FileWork.SaveAsFile(ref note, ref tbChange, ref docPath); FileWork.CreateFile(ref note, ref tbChange, ref docPath); } } else if (message == DialogResult.No) { FileWork.CreateFile(ref note, ref tbChange, ref docPath); } } else { FileWork.CreateFile(ref note, ref tbChange, ref docPath); } }; open.Click += (s, a) => { if (tbChange == true) { DialogResult message = MessageBox.Show("Сохранить текущий документ перед открытием нового?", "Открытие документа", MessageBoxButtons.YesNoCancel); if (message == DialogResult.Yes) { if (docPath != "") { FileWork.SaveFile(ref note, ref tbChange, ref docPath); FileWork.OpenFile(ref note, ref tbChange, ref docPath); } else if (docPath == "") { FileWork.SaveAsFile(ref note, ref tbChange, ref docPath); FileWork.OpenFile(ref note, ref tbChange, ref docPath); } } else if (message == DialogResult.No) { FileWork.OpenFile(ref note, ref tbChange, ref docPath); } else { return; } } else { FileWork.OpenFile(ref note, ref tbChange, ref docPath); } }; save.Click += (s, a) => { if (docPath != "") { FileWork.SaveFile(ref note, ref tbChange, ref docPath); } else { FileWork.SaveAsFile(ref note, ref tbChange, ref docPath); } }; saveAs.Click += (s, a) => { FileWork.SaveAsFile(ref note, ref tbChange, ref docPath); }; pageParameters.Click += (s, a) => { if (pageSetupDialog.ShowDialog() == DialogResult.OK) { printDocument.DefaultPageSettings = pageSetupDialog.PageSettings; } }; print.Click += (s, a) => { if (printDialog.ShowDialog() == DialogResult.OK) { try { printDocument.Print(); } catch (Exception) { MessageBox.Show("Ошибка параметров печати.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }; // Отправка документа на печать printDocument.PrintPage += (s, a) => { a.Graphics.DrawString(note.Text, note.Font, Brushes.Black, 10, 10); }; exit.Click += (s, a) => { Application.Exit(); }; // ----------------------- Меню Edit ----------------------------------------------- undo.Click += (s, a) => { note.Undo(); }; cut.Click += (s, a) => { if (note.SelectionLength > 0) { note.Cut(); } }; copy.Click += (s, a) => { if (note.SelectionLength > 0) { note.Copy(); } }; paste.Click += (s, a) => { note.Paste(); }; delete.Click += (s, a) => { if (note.SelectionLength > 0) { note.SelectedText = ""; } }; findReplace.Click += (s, a) => { SearchForm findText = new SearchForm { Owner = this }; findText.Show(); }; go.Click += (s, a) => { GoToForm gotoform = new GoToForm { Owner = this }; gotoform.tbLineNum.Minimum = 0; gotoform.tbLineNum.Maximum = note.Lines.Count(); gotoform.ShowDialog(); }; giveAll.Click += (s, a) => { note.SelectAll(); }; timeDate.Click += (s, a) => { note.AppendText(Environment.NewLine + Convert.ToString(System.DateTime.Now)); }; // ----------------------- Меню Format ----------------------------------------------- wordWrap.Click += (s, a) => { if (wordWrap.CheckState == CheckState.Checked) { note.WordWrap = true; note.ScrollBars = ScrollBars.Vertical; go.Enabled = false; statusLab1.Visible = false; statusLinesCount.Visible = false; } else { note.WordWrap = false; note.ScrollBars = ScrollBars.Both; go.Enabled = true; statusLab1.Visible = true; statusLinesCount.Visible = true; } }; font.Click += (s, a) => { fontDialog.Font = note.Font; DialogResult = fontDialog.ShowDialog(); if (DialogResult == DialogResult.OK) { note.Font = fontDialog.Font; } }; // ----------------------- Меню View ----------------------------------------------- statusBar.Click += (s, a) => { if (statusBar.CheckState == CheckState.Checked) { statusBar.Visible = true; } else { statusBar.Visible = false; } }; }