using System; using System.Windows.Forms; namespace WinFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void CalcBtn_Click(object sender, EventArgs e) { if (!GetAB(out int a, out int b)) { MessageBox.Show("Incorrect values."); return; } var obj = new B(a, b); InfoListBox.Items.Add($"{a} + {b} + 15 = {obj.M}"); } private void CalcDefaultBtn_Click(object sender, EventArgs e) { if (!GetAB(out int a, out int b)) { MessageBox.Show("Incorrect values."); return; } var obj = new B(); InfoListBox.Items.Add($"3 + 5 + 15 = {obj.M}"); } private void ShowC1Btn_Click(object sender, EventArgs e) { if (!GetAB(out int a, out int b)) { MessageBox.Show("Incorrect values."); return; } var obj = new A(a, b); InfoListBox.Items.Add($"a++ = {obj.C1}"); } private void ShowC2Btn_Click(object sender, EventArgs e) { if (!GetAB(out int a, out int b)) { MessageBox.Show("Incorrect values."); return; } var obj = new A(a, b); InfoListBox.Items.Add($"b++ = {obj.C2}"); } private bool GetAB(out int a, out int b) { try { a = int.Parse(AValueTextBox.Text); b = int.Parse(BValueTextBox.Text); return true; } catch { a = b = 0; return false; } } } }