/// <summary> /// Создает новый экземпляр формы. /// </summary> /// <param name="element">Элемент для редактирования.</param> public ElementDetailForm(IElement element = null) { InitializeComponent(); capacitorElementControl.Location = new Point(12, 52); resistorElementControl.Location = new Point(12, 52); inductorElementControl.Location = new Point(12, 52); Size = new Size(286, 198); if (element != null) { if (element is Resistor) { _elementControl = resistorElementControl; componentTypeComboBox.SelectedIndex = 2; } else if (element is Capacitor) { _elementControl = capacitorElementControl; componentTypeComboBox.SelectedIndex = 0; } else if (element is Inductor) { _elementControl = inductorElementControl; componentTypeComboBox.SelectedIndex = 1; } _elementControl.Visible = true; _elementControl.Element = element; } }
/// <summary> /// Выбор типа элемента. /// </summary> /// <param name="sender">Источник события.</param> /// <param name="e">Аргументы.</param> private void ComponentTypeComboBoxSelectedIndexChanged(object sender, EventArgs e) { capacitorElementControl.Visible = componentTypeComboBox.SelectedIndex == 0; inductorElementControl.Visible = componentTypeComboBox.SelectedIndex == 1; resistorElementControl.Visible = componentTypeComboBox.SelectedIndex == 2; _elementControl = componentTypeComboBox.SelectedIndex == 0 ? capacitorElementControl : _elementControl; _elementControl = componentTypeComboBox.SelectedIndex == 1 ? inductorElementControl : _elementControl; _elementControl = componentTypeComboBox.SelectedIndex == 2 ? resistorElementControl : _elementControl; }