public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { editorValue = value; if ((provider != null) && (((IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService))) != null)) { if (this.editorDialog == null) { this.editorDialog = new GradientColorPickerForm(); } GradientDefinition colors = editorValue as GradientDefinition; if (colors != null) { editorDialog.GradientColors = colors; } IntPtr focus = GetFocus(); try { if (editorDialog.ShowDialog() == DialogResult.OK) { editorValue = editorDialog.GradientColors; } } finally { if (focus != IntPtr.Zero) { SetFocus(new HandleRef(null, focus)); } } } value = editorValue; editorValue = null; return(value); }
public RectangleShape() { strokeWidth = 1; strokeColor = Color.Black; fillColor = Color.Orange; gradientColors = new GradientDefinition(); useGradient = false; useStroke = false; this.WidthInUnits = 3; this.HeightInUnits = 1; }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(string)) { GradientDefinition colors = value as GradientDefinition; string c1 = string.Format("Color1={0};{1};{2};", colors.Color1.R, colors.Color1.G, colors.Color1.B); string c2 = string.Format("Color2={0};{1};{2};", colors.Color2.R, colors.Color2.G, colors.Color2.B); return(string.Format("{0} {1}", c1, c2)); } return(base.ConvertTo(context, culture, value, destinationType)); }
public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues) { if (propertyValues == null) { throw new ArgumentNullException("propertyValues"); } // we allow user to change only next gradient values: Color c1 = (Color)propertyValues["Color1"]; Color c2 = (Color)propertyValues["Color2"]; GradientType gt = (GradientType)propertyValues["GradientType"]; GradientDefinition gd = ((RectangleShape)context.Instance).GradientDefinition; //and another (Point1, Point2) are just copyed from instance item... return(new GradientDefinition(c1, c2, gd.Point1, gd.Point2, gt)); }