コード例 #1
0
 /// <summary>
 /// 
 /// </summary>
 public void penControl_PenChangedEvent(PenControl control)
 {
     SetObjectPropertyValueByTag(control.Tag, control.Pen);
 }
コード例 #2
0
        /// <summary>
        /// Helper to create the corresponding control.
        /// </summary>
        protected void AddDynamicPropertyValueControl(string propertyName, Type propertyType, object value, object tag, bool isReadOnly, ref int yLocation)
        {
            if (propertyType == null)
            {
                return;
            }

            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.BorderStyle = BorderStyle.FixedSingle;
                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)
                || propertyType == typeof(decimal))
            {
                AddDynamicPropertyLabel(propertyName, ref yLocation);

                NumericUpDown propertyValueNumeric = new NumericUpDown();
                propertyValueNumeric.BorderStyle = BorderStyle.FixedSingle;

                if (propertyType == typeof(double) || propertyType == typeof(float)
                    || propertyType == typeof(decimal))
                {
                    propertyValueNumeric.DecimalPlaces = 4;
                }

                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();
                propertyValue.FlatStyle = FlatStyle.Popup;
                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 if (propertyType == typeof(Brush) ||
                propertyType.IsSubclassOf(typeof(Brush)))
            {
                BrushControl brushControl = new BrushControl();
                control = brushControl;
                brushControl.BorderStyle = BorderStyle.FixedSingle;
                brushControl.Brush = (Brush)value;
                brushControl.BrushChangedEvent += new BrushControl.BrushChangedDelegate(brushControl_BrushsChangedEvent);
                brushControl.Tag = tag;
                brushControl.BrushName = propertyName;
                brushControl.ReadOnly = isReadOnly;
            }
            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;
            }
        }