private void numericUpDown_ValueChanged(object sender, EventArgs e) { if (!_valueWasAssigned) { return; } if (_property.Attribute is DesignerFloat) { _property.Property.SetValue(_object, (float)numericUpDown.Value, null); } if (_property.Attribute is DesignerInteger) { _property.Property.SetValue(_object, (int)numericUpDown.Value, null); } if (_property.Attribute is DesignerFlexibleFloat) { FlexiblePropertyFloat flexProp = (FlexiblePropertyFloat)_property.Property.GetValue(_object, null); flexProp.Min = (float)numericUpDown.Value; flexProp.Max = (float)numericUpDown.Value; } if (_property.Attribute is DesignerFlexibleInteger) { FlexiblePropertyInteger flexProp = (FlexiblePropertyInteger)_property.Property.GetValue(_object, null); flexProp.Min = (int)numericUpDown.Value; flexProp.Max = (int)numericUpDown.Value; } OnValueChanged(); }
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; } }