private void ResistanceTextBox_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         ResistanceStopEditing(sender);
     }
     if (e.Key == Key.Escape)
     {
         TextBox  tb  = sender as TextBox;
         Resistor res = tb.DataContext as Resistor;
         tb.Text = res.Resistance.ToString();
         Keyboard.ClearFocus();
     }
 }
        private void ResistanceStopEditing(object sender)
        {
            TextBox  tb  = sender as TextBox;
            Resistor res = tb.DataContext as Resistor;
            double   resistance;

            double.TryParse(tb.Text, out resistance);
            res.Resistance = resistance;

            if (cbRun.IsChecked == true)
            {
                if (!RunLayout())
                {
                    StopSim();
                }
            }
            Keyboard.ClearFocus();
        }
Пример #3
0
        private void SaveData()
        {
            Element element = Tag as Element;

            element.Name = tbName.Text;

            if (element is Resistor)
            {
                Resistor resistor = element as Resistor;
                resistor.Resistance     = double.Parse(tbResistance.Text);
                resistor.IsEditable     = cbEditable.IsChecked == true;
                resistor.DisplayVoltage = cbVoltage.IsChecked == true;
            }
            else if (element is Reohord)
            {
                Reohord reohord = element as Reohord;
                reohord.Resistance    = double.Parse(tbResistance.Text);
                reohord.DisplayLength = cbReohordDisplayMode.SelectedIndex == 0;
            }
            else if (element is Battery)
            {
                Battery battery = element as Battery;
                battery.Resistance     = double.Parse(tbResistance.Text);
                battery.Eds            = double.Parse(tbEds.Text);
                battery.DisplayVoltage = cbVoltage.IsChecked == true;
            }
            else if (element is Amperemeter)
            {
                Amperemeter galvanometr = element as Amperemeter;
                galvanometr.Division = double.Parse(tbDivision.Text);
            }
            else if (element is Potentiometer)
            {
                Potentiometer pot = element as Potentiometer;
                pot.MaxResistance  = double.Parse(tbMaxResistance.Text);
                pot.DisplayVoltage = cbVoltage.IsChecked == true;
            }
        }