/// <summary>
 ///
 /// </summary>
 public void penControl_PenChangedEvent(PenControl control)
 {
     SetObjectPropertyValueByTag(control.Tag, control.Pen);
 }
        /// <summary>
        /// Helper to create the corresponding control.
        /// </summary>
        protected void AddDynamicPropertyValueControl(string propertyName, Type propertyType, object value, object tag, bool isReadOnly, ref int yLocation)
        {
            Control control = null;

            if (propertyType.IsEnum)
            {
                AddDynamicPropertyLabel(propertyName, ref yLocation);

                string stringValue = value.ToString();

                ComboBox propertyValuesComboBox = new ComboBox();
                control = propertyValuesComboBox;
                propertyValuesComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                propertyValuesComboBox.Enabled       = !isReadOnly;
                string[] names = Enum.GetNames(propertyType);
                propertyValuesComboBox.Items.AddRange(names);

                for (int i = 0; i < propertyValuesComboBox.Items.Count; i++)
                {
                    if (propertyValuesComboBox.Items[i].ToString() == stringValue)
                    {
                        propertyValuesComboBox.SelectedIndex = i;
                        break;
                    }
                }

                //propertyValuesComboBox.Top = yLocation;
                propertyValuesComboBox.Tag = tag;

                propertyValuesComboBox.SelectedIndexChanged += new EventHandler(propertyValues_SelectedIndexChanged);
            }
            if (propertyType == typeof(string))
            {
                AddDynamicPropertyLabel(propertyName, ref yLocation);

                TextBox textBox = new TextBox();
                textBox.Text = (string)value;

                textBox.Enabled = !isReadOnly;
                textBox.Tag     = tag;
                //textBox.Top = yLocation;
                control              = textBox;
                textBox.TextChanged += new EventHandler(textBox_TextChanged);
            }
            if (propertyType == typeof(double) ||
                propertyType == typeof(float) ||
                propertyType == typeof(int) ||
                propertyType == typeof(short) ||
                propertyType == typeof(long))
            {
                AddDynamicPropertyLabel(propertyName, ref yLocation);

                NumericUpDown propertyValueNumeric = new NumericUpDown();
                control = propertyValueNumeric;
                propertyValueNumeric.ReadOnly = isReadOnly;
                // Enabled also needed, since readonly only blocks text, not up down buttons.
                propertyValueNumeric.Enabled = !isReadOnly;
                propertyValueNumeric.Minimum = decimal.MinValue;
                propertyValueNumeric.Maximum = decimal.MaxValue;
                propertyValueNumeric.Value   = decimal.Parse(value.ToString());
                propertyValueNumeric.Tag     = tag;
                //propertyValueNumeric.Top = yLocation;
                propertyValueNumeric.ValueChanged += new EventHandler(propertyValue_ValueChanged);
            }
            else if (propertyType == typeof(bool))
            {
                CheckBox propertyValue = new CheckBox();
                control = propertyValue;
                propertyValue.Checked = (bool)value;
                propertyValue.Text    = propertyName;
                propertyValue.Enabled = !isReadOnly;
                //propertyValue.Top = yLocation;
                propertyValue.Tag             = tag;
                propertyValue.CheckedChanged += new EventHandler(propertyValue_CheckedChanged);
            }
            else if (propertyType == typeof(Pen))
            {
                PenControl penControl = new PenControl();
                control = penControl;
                penControl.BorderStyle      = BorderStyle.FixedSingle;
                penControl.Pen              = (Pen)value;
                penControl.PenChangedEvent += new PenControl.PenChangedDelegate(penControl_PenChangedEvent);
                penControl.Tag              = tag;
                penControl.PenName          = propertyName;
                penControl.ReadOnly         = IsReadOnly;
                //penControl.Top = yLocation;
            }
            else
            {
                //SystemMonitor.Error("Failed to display indicator property type [" + propertyType.Name + "].");
            }

            if (control != null)
            {
                control.Top = yLocation;

                propertiesControls.Add(control);
                this.Controls.Add(control);
                yLocation = control.Bottom + InterControlMargin;

                control.Width = this.Width - InterControlMargin;
                this.Height   = control.Bottom;
            }
        }