// This code allows the designer to generate the Fill constructor

            /// <summary>
            /// Converts the given value object to the specified type, using the specified context and culture information.
            /// </summary>
            /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
            /// <param name="culture">A <see cref="T:System.Globalization.CultureInfo" />. If null is passed, the current culture is assumed.</param>
            /// <param name="value">The <see cref="T:System.Object" /> to convert.</param>
            /// <param name="destinationType">The <see cref="T:System.Type" /> to convert the <paramref name="value" /> parameter to.</param>
            /// <returns>An <see cref="T:System.Object" /> that represents the converted value.</returns>
            public override object ConvertTo(ITypeDescriptorContext context,
                                             CultureInfo culture,
                                             object value,
                                             Type destinationType)
            {
                if (value is BrushPainter2)
                {
                    if (destinationType == typeof(string))
                    {
                        // Display string in designer
                        return("(BrushPainter2)");
                    }
                    else if (destinationType == typeof(InstanceDescriptor))
                    {
                        BrushPainter2 filler = (BrushPainter2)value;

                        if (filler.FillType == BrushPainter2Type.Solid)
                        {
                            ConstructorInfo ctor = typeof(BrushPainter2).GetConstructor(new Type[] { typeof(Color) });
                            if (ctor != null)
                            {
                                return(new InstanceDescriptor(ctor, new object[] { filler.SolidColor }));
                            }
                        }
                        else if (filler.FillType == BrushPainter2Type.Hatch)
                        {
                            ConstructorInfo ctor = typeof(BrushPainter2).GetConstructor(new Type[] { typeof(HatchStyle),
                                                                                                     typeof(Color),
                                                                                                     typeof(Color) });
                            if (ctor != null)
                            {
                                return(new InstanceDescriptor(ctor, new object[] { filler.HatchStyle,
                                                                                   filler.HatchColor,
                                                                                   filler.BackColor }));
                            }
                        }
                        else if (filler.FillType == BrushPainter2Type.Gradient)
                        {
                            ConstructorInfo ctor = typeof(BrushPainter2).GetConstructor(new Type[] { typeof(Color[]),
                                                                                                     typeof(float[]) });
                            if (ctor != null)
                            {
                                return(new InstanceDescriptor(ctor, new object[] { filler.GradientColors.Colors,
                                                                                   filler.GradientColors.Positions }));
                            }
                        }
                        else
                        {
                            ConstructorInfo ctor = typeof(BrushPainter2).GetConstructor(Type.EmptyTypes);
                            if (ctor != null)
                            {
                                return(new InstanceDescriptor(ctor, null));
                            }
                        }
                    }
                }
                return(base.ConvertTo(context, culture, value, destinationType));
            }
        /// <summary>
        /// Initializes a new instance of <c>BrushPainter2EditorDialog</c> using an existing <c>BrushPainter2</c>
        /// at the default window position.
        /// </summary>
        /// <param name="filler">Existing <c>BrushPainter2</c> object.</param>
        /// <exception cref="ArgumentNullException">filler</exception>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="filler" /> is null.</exception>
        public BrushPainter2EditorDialog(BrushPainter2 filler)
        {
            if (filler == null)
            {
                throw new ArgumentNullException("filler");
            }

            InitializeComponent();
            AdjustDialogSize();
            SetControlsToInitialValues(filler);
        }
 /// <summary>
 /// Handles the Click event of the okButton control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void okButton_Click(object sender, EventArgs e)
 {
     if (solidRadioButton.Checked)
     {
         filler = new BrushPainter2(FromLabelNud(solidColorLabel, solidAlphaNud));
     }
     else if (hatchRadioButton.Checked)
     {
         filler = new BrushPainter2(hatchComboBox.SelectedHatchStyle,
                                    FromLabelNud(hatchColorLabel, hatchAlphaNud),
                                    FromLabelNud(backColorLabel, backAlphaNud));
     }
     else if (gradientRadioButton.Checked)
     {
         filler = new BrushPainter2(gradientEditor.Blend);
     }
     else
     {
         filler = BrushPainter2.Empty();
     }
     DialogResult = DialogResult.OK;
 }
        /// <summary>
        /// Sets the controls to initial values.
        /// </summary>
        /// <param name="filler">The filler.</param>
        private void SetControlsToInitialValues(BrushPainter2 filler)
        {
            Init(filler.SolidColor, solidColorLabel, solidAlphaNud);
            Init(filler.HatchColor, hatchColorLabel, hatchAlphaNud);
            Init(filler.BackColor, backColorLabel, backAlphaNud);
            gradientEditor.Blend = filler.GradientColors;

            hatchComboBox.SelectedIndex = 0;
            for (int i = 0; i < hatchComboBox.Items.Count; i++)
            {
                if (filler.HatchStyle == (HatchStyle)(hatchComboBox.Items[i]))
                {
                    hatchComboBox.SelectedIndex = i;
                }
            }
            UpdateHatch();

            UpdateSolid();

            if (filler.FillType == BrushPainter2Type.None)
            {
                noneRadioButton.Checked = true;
            }
            else if (filler.FillType == BrushPainter2Type.Solid)
            {
                solidRadioButton.Checked = true;
            }
            else if (filler.FillType == BrushPainter2Type.Hatch)
            {
                hatchRadioButton.Checked = true;
            }
            else
            {
                gradientRadioButton.Checked = true;
            }
        }
 /// <summary>
 /// Initializes a new instance of <c>BrushPainter2EditorDialog</c> using an existing <c>BrushPainter2</c>
 /// and positioned beneath the specified control.
 /// </summary>
 /// <param name="filler">Existing <c>BrushPainter2</c> object.</param>
 /// <param name="c">Control beneath which the dialog should be placed.</param>
 /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="filler" /> is null.</exception>
 public BrushPainter2EditorDialog(BrushPainter2 filler, Control c) : this(filler)
 {
     Utils.SetStartPositionBelowControl(this, c);
 }
 /// <summary>
 /// Initializes a new instance of <c>BrushPainter2EditorDialog</c> using an empty <c>BrushPainter2</c>
 /// and positioned beneath the specified control.
 /// </summary>
 /// <param name="c">Control beneath which the dialog should be placed.</param>
 public BrushPainter2EditorDialog(Control c) : this(BrushPainter2.Empty(), c)
 {
 }
 /// <summary>
 /// Initializes a new instance of <c>BrushPainter2EditorDialog</c> using an empty <c>BrushPainter2</c>
 /// at the default window position.
 /// </summary>
 public BrushPainter2EditorDialog() : this(BrushPainter2.Empty())
 {
 }