示例#1
0
        public override void SetParameter(MethodDef.Param param, object obj)
        {
            base.SetParameter(param, obj);

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

            if (restFloatAtt != null)
            {
                SetRange(restFloatAtt.Precision,
                         (decimal)restFloatAtt.Min,
                         (decimal)restFloatAtt.Max,
                         (decimal)restFloatAtt.Steps,
                         restFloatAtt.Units);
            }

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

            if (restIntAtt != null)
            {
                SetRange(0,
                         (decimal)restIntAtt.Min,
                         (decimal)restIntAtt.Max,
                         (decimal)restIntAtt.Steps,
                         restIntAtt.Units);
            }

            // extract the value
            decimal value = 0;

            DesignerFloat floatAtt = param.Attribute as DesignerFloat;

            if (floatAtt != null)
            {
                float val = (param.Value != null) ? float.Parse(param.Value.ToString()) : 0.0f;
                value = (decimal)val;
                numericUpDown.DecimalPlaces = 2;
            }

            DesignerInteger intAtt = param.Attribute as DesignerInteger;

            if (intAtt != null)
            {
                int val = (param.Value != null) ? int.Parse(param.Value.ToString()) : 0;
                value = (decimal)val;
            }

            // assign value within limits
            numericUpDown.Value = Math.Max(numericUpDown.Minimum, Math.Min(numericUpDown.Maximum, value));
        }
示例#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)
            {
                SetRange(restFloatAtt.Precision,
                         (decimal)restFloatAtt.Min,
                         (decimal)restFloatAtt.Max,
                         (decimal)restFloatAtt.Steps,
                         restFloatAtt.Units);
            }

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

            if (restIntAtt != null)
            {
                SetRange(0,
                         (decimal)restIntAtt.Min,
                         (decimal)restIntAtt.Max,
                         (decimal)restIntAtt.Steps,
                         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));
        }