public override void SetProperty(DesignerPropertyInfo property, object obj)
        {
            base.SetProperty(property, obj);

            DesignerFloat floatAtt = property.Attribute as DesignerFloat;

            if (floatAtt != null)
            {
                numericUpDown.DecimalPlaces = floatAtt.Precision;
                numericUpDown.Minimum       = (decimal)floatAtt.Min;
                numericUpDown.Maximum       = (decimal)floatAtt.Max;
                numericUpDown.Increment     = (decimal)floatAtt.Steps;

                float val = (float)property.Property.GetValue(obj, null);
                numericUpDown.Value = (decimal)val;

                unitLabel.Text = floatAtt.Units;
            }

            DesignerInteger intAtt = property.Attribute as DesignerInteger;

            if (intAtt != null)
            {
                numericUpDown.DecimalPlaces = 0;
                numericUpDown.Minimum       = (decimal)intAtt.Min;
                numericUpDown.Maximum       = (decimal)intAtt.Max;
                numericUpDown.Increment     = (decimal)intAtt.Steps;

                int val = (int)property.Property.GetValue(obj, null);
                numericUpDown.Value = (decimal)val;

                unitLabel.Text = intAtt.Units;
            }

            DesignerFlexibleFloat flexFloatAtt = property.Attribute as DesignerFlexibleFloat;

            if (flexFloatAtt != null)
            {
                numericUpDown.DecimalPlaces = flexFloatAtt.Precision;
                numericUpDown.Minimum       = (decimal)flexFloatAtt.Min;
                numericUpDown.Maximum       = (decimal)flexFloatAtt.Max;
                numericUpDown.Increment     = (decimal)flexFloatAtt.Steps;

                FlexiblePropertyFloat flexProp = (FlexiblePropertyFloat)property.Property.GetValue(obj, null);
                numericUpDown.Value = (decimal)flexProp.Min;

                unitLabel.Text = flexFloatAtt.Units;
            }

            DesignerFlexibleInteger flexIntegerAtt = property.Attribute as DesignerFlexibleInteger;

            if (flexIntegerAtt != null)
            {
                numericUpDown.DecimalPlaces = 0;
                numericUpDown.Minimum       = (decimal)flexIntegerAtt.Min;
                numericUpDown.Maximum       = (decimal)flexIntegerAtt.Max;
                numericUpDown.Increment     = (decimal)flexIntegerAtt.Steps;

                FlexiblePropertyInteger flexProp = (FlexiblePropertyInteger)property.Property.GetValue(obj, null);
                numericUpDown.Value = (decimal)flexProp.Min;

                unitLabel.Text = flexIntegerAtt.Units;
            }
        }
Ejemplo n.º 2
0
        public override void SetProperty(DesignerPropertyInfo property, object obj)
        {
            base.SetProperty(property, obj);

            // check if there is an override for this paroperty
            Nodes.Node node = _object as Nodes.Node;
            if (node != null && node.HasOverrride(property.Property.Name))
            {
                numericUpDown.Enabled = false;

                return;
            }

            DesignerPropertyInfo restrictions = property;

            bool linkBroken;
            DesignerPropertyInfo linkedProperty = property.Attribute.GetLinkedProperty(obj, out linkBroken);

            // control cannot be used with a broken link
            if (linkBroken)
            {
                numericUpDown.Enabled = false;

                return;
            }

            // if we have a linked property this property will define the restrictions
            if (linkedProperty.Property != null)
            {
                restrictions = linkedProperty;
            }

            // extract resrictions for float property
            DesignerFloat restFloatAtt = restrictions.Attribute as DesignerFloat;

            if (restFloatAtt != null)
            {
                numericUpDown.DecimalPlaces = restFloatAtt.Precision;
                numericUpDown.Minimum       = (decimal)restFloatAtt.Min;
                numericUpDown.Maximum       = (decimal)restFloatAtt.Max;
                numericUpDown.Increment     = (decimal)restFloatAtt.Steps;

                unitLabel.Text = restFloatAtt.Units;
            }

            // extract restrictions for int property
            DesignerInteger restIntAtt = restrictions.Attribute as DesignerInteger;

            if (restIntAtt != null)
            {
                numericUpDown.DecimalPlaces = 0;
                numericUpDown.Minimum       = (decimal)restIntAtt.Min;
                numericUpDown.Maximum       = (decimal)restIntAtt.Max;
                numericUpDown.Increment     = (decimal)restIntAtt.Steps;

                unitLabel.Text = restIntAtt.Units;
            }

            // extract the value
            decimal value = 0;

            DesignerFloat floatAtt = property.Attribute as DesignerFloat;

            if (floatAtt != null)
            {
                float val = (float)property.Property.GetValue(obj, null);

                value = (decimal)val;
            }

            DesignerInteger intAtt = property.Attribute as DesignerInteger;

            if (intAtt != null)
            {
                int val = (int)property.Property.GetValue(obj, null);

                value = (decimal)val;
            }

            // assign value within limits
            numericUpDown.Value = Math.Max(numericUpDown.Minimum, Math.Min(numericUpDown.Maximum, value));
        }