Ну лови. Метки он поставит...
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
comboBox1.Items.AddRange([new Converter("kg", 1), new Converter("mg", 1e-6), new Converter("g", 1e-3), new Converter("t", 1000)]);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
try
{
double d = double.Parse(textBox1.Text);
textBox2.Text = ((Converter)comboBox1.SelectedItem)[d].ToString();
}
catch
{
textBox2.Text = string.Empty;
}
}
}
public class Converter
{
private double ConversionFactor = 1;
private string UnitName;
public Converter(string _UnitName, double _ConversionFactor)
{
UnitName = _UnitName;
ConversionFactor = _ConversionFactor;
}
public override string ToString()
{
return UnitName;
}
public double this[double _Value] { get => _Value * ConversionFactor; }
}
}