using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); comboBox1.SelectedIndex = 0; comboBox2.SelectedIndex = 0; textBox1.Text = "1"; } private double getValue(string a, string b) { double finalValue = 1; double aValue = 1; double bValue= 1; if (a == "грамм") aValue = 1; if (b == "грамм") bValue = 1; if (a == "килограмм") aValue = 1000; if (b == "килограмм") bValue = 1000; if (a == "центнер") aValue = 100000; if (b == "центнер") bValue = 100000; if (a == "тонна") aValue = 1000000; if (b == "тонна") bValue = 1000000; finalValue = aValue / bValue; return finalValue; } private void button1_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(this.textBox1.Text) || String.IsNullOrEmpty(this.textBox2.Text)) { double result = 1; result = Convert.ToDouble(this.textBox1.Text) * getValue(this.comboBox1.Text, this.comboBox2.Text); this.textBox2.Text = Convert.ToString(result); } } } }