private void okButton_Click(object sender, EventArgs e)
 {
     if (solidRadioButton.Checked)
     {
         filler = new BrushPainter(FromLabelNud(solidColorLabel, solidAlphaNud));
     }
     else if (hatchRadioButton.Checked)
     {
         filler = new BrushPainter(hatchComboBox.SelectedHatchStyle,
                                   FromLabelNud(hatchColorLabel, hatchAlphaNud),
                                   FromLabelNud(backColorLabel, backAlphaNud));
     }
     else if (gradientRadioButton.Checked)
     {
         if (gradientTypeComboBox.SelectedIndex == gradientLinear)
         {
             filler = new BrushPainter((float)gradientAngleNud.Value, gradientEditor.Blend);
         }
         else if (gradientTypeComboBox.SelectedIndex == gradientPathRect)
         {
             filler = new BrushPainter(BrushPathGradientType.Rect, gradientEditor.Blend);
         }
         else
         {
             filler = new BrushPainter(BrushPathGradientType.Radial, gradientEditor.Blend);
         }
     }
     else
     {
         filler = BrushPainter.Empty();
     }
     DialogResult = DialogResult.OK;
 }
        private void SetControlsToInitialValues(BrushPainter filler)
        {
            // Fill with defaults
            Init(filler.SolidColor, solidColorLabel, solidAlphaNud);
            Init(filler.HatchColor, hatchColorLabel, hatchAlphaNud);
            Init(filler.BackColor, backColorLabel, backAlphaNud);
            gradientEditor.Blend = filler.GradientColors;

            if (filler.FillType == BrushPainterType.PathGradient)
            {
                if (filler.BrushPathGradientType == BrushPathGradientType.Rect)
                {
                    gradientTypeComboBox.SelectedIndex = gradientPathRect;
                }
                else
                {
                    gradientTypeComboBox.SelectedIndex = gradientPathRadial;
                }
            }
            else
            {
                gradientTypeComboBox.SelectedIndex = gradientLinear;
                gradientAngleNud.Value             = (decimal)filler.LinearGradientAngle;
            }
            UpdateGradient();

            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 == BrushPainterType.None)
            {
                noneRadioButton.Checked = true;
            }
            else if (filler.FillType == BrushPainterType.Solid)
            {
                solidRadioButton.Checked = true;
            }
            else if (filler.FillType == BrushPainterType.Hatch)
            {
                hatchRadioButton.Checked = true;
            }
            else
            {
                gradientRadioButton.Checked = true;
            }
        }
        /// <summary>
        ///     Initializes a new instance of <c>BrushPainterEditorDialog</c> using an existing <c>BrushPainter</c>
        ///     at the default window position.
        /// </summary>
        /// <param name="filler">Existing <c>BrushPainter</c> object.</param>
        /// <exception cref="System.ArgumentNullException">
        ///		Thrown if <paramref name="filler" /> is null.
        ///	</exception>
        public BrushPainterEditorDialog(BrushPainter filler)
        {
            if (filler == null)
            {
                throw new ArgumentNullException("filler");
            }

            InitializeComponent();
            FillGradientComboBox();
            AdjustDialogSize();
            SetControlsToInitialValues(filler);
        }
 /// <summary>
 ///		Initializes a new instance of <c>BrushPainterEditorDialog</c> using an existing <c>BrushPainter</c>
 ///		and positioned beneath the specified control.
 /// </summary>
 /// <param name="filler">Existing <c>BrushPainter</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 BrushPainterEditorDialog(BrushPainter filler, Control c) : this(filler)
 {
     Utils.SetStartPositionBelowControl(this, c);
 }
 /// <summary>
 ///		Initializes a new instance of <c>BrushPainterEditorDialog</c> using an empty <c>BrushPainter</c>
 ///		and positioned beneath the specified control.
 /// </summary>
 /// <param name="c">Control beneath which the dialog should be placed.</param>
 public BrushPainterEditorDialog(Control c) : this(BrushPainter.Empty(), c)
 {
 }
 /// <summary>
 ///		Initializes a new instance of <c>BrushPainterEditorDialog</c> using an empty <c>BrushPainter</c>
 ///     at the default window position.
 /// </summary>
 public BrushPainterEditorDialog() : this(BrushPainter.Empty())
 {
 }
Exemplo n.º 7
0
            // This code allows the designer to generate the Fill constructor

            public override object ConvertTo(ITypeDescriptorContext context,
                                             CultureInfo culture,
                                             object value,
                                             Type destinationType)
            {
                if (destinationType == typeof(string))
                {
                    // Display string in designer
                    return("(BrushPainter)");
                }
                else if (destinationType == typeof(InstanceDescriptor) && value is BrushPainter)
                {
                    BrushPainter filler = (BrushPainter)value;

                    if (filler.FillType == BrushPainterType.Solid)
                    {
                        ConstructorInfo ctor = typeof(BrushPainter).GetConstructor(new Type[] { typeof(Color) });
                        if (ctor != null)
                        {
                            return(new InstanceDescriptor(ctor, new object[] { filler.SolidColor }));
                        }
                    }
                    else if (filler.FillType == BrushPainterType.Hatch)
                    {
                        ConstructorInfo ctor = typeof(BrushPainter).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 == BrushPainterType.LinearGradient)
                    {
                        ConstructorInfo ctor = typeof(BrushPainter).GetConstructor(new Type[] { typeof(float),
                                                                                                typeof(Color[]),
                                                                                                typeof(float[]) });
                        if (ctor != null)
                        {
                            return(new InstanceDescriptor(ctor, new object[] { filler.LinearGradientAngle,
                                                                               filler.GradientColors.Colors,
                                                                               filler.GradientColors.Positions }));
                        }
                    }
                    else if (filler.FillType == BrushPainterType.PathGradient)
                    {
                        ConstructorInfo ctor = typeof(BrushPainter).GetConstructor(new Type[] { typeof(BrushPathGradientType),
                                                                                                typeof(Color[]),
                                                                                                typeof(float[]) });
                        if (ctor != null)
                        {
                            return(new InstanceDescriptor(ctor, new object[] { filler.BrushPathGradientType,
                                                                               filler.GradientColors.Colors,
                                                                               filler.GradientColors.Positions }));
                        }
                    }
                    else
                    {
                        ConstructorInfo ctor = typeof(BrushPainter).GetConstructor(Type.EmptyTypes);
                        if (ctor != null)
                        {
                            return(new InstanceDescriptor(ctor, null));
                        }
                    }
                }

                return(base.ConvertTo(context, culture, value, destinationType));
            }