How to transfer the selected text parameters from the second form to the first one, by pressing the "apply" button in the second form, without violating the principles of OOP?
Form1:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void font_button_Click(object sender, EventArgs e) { Form2 font_dialog = new Form2(); font_dialog.ShowDialog(); } private void textBox1_TextChanged(object sender, EventArgs e) { } // Кнопка сохранения файла в заранее указанную папку private void save_button_Click(object sender, EventArgs e) { Directory.CreateDirectory("C:\\my_dir"); // Создание директории // Запись string lines = "" + textBox1.Text; File.WriteAllText(@"C:\\my_dir\my_txt.txt", lines); MessageBox.Show("Файл сохранен!"); } private void exit_button_Click(object sender, EventArgs e) { this.Close(); } } } Form2:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } // Список шрифтов private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBox1.Text) { case "Arial": Font font_1 = new Font("Arial", this.Font.Size); comboBox1.Font = font_1; break; case "Courier New": Font font_2 = new Font("Courier New", this.Font.Size); comboBox1.Font = font_2; break; case "Times New Roman": Font font_3 = new Font("Times New Roman", this.Font.Size); comboBox1.Font = font_3; break; default: Font def_font = new Font("Arial", this.Font.Size); comboBox1.Font = def_font; break; } } // Кнопка применения параметров шрифта private void OK_Click(object sender, EventArgs e) { } private void numericUpDown1_ValueChanged(object sender, EventArgs e) { } } }