Ejemplo n.º 1
0
            // This code allows the designer to generate the Fill constructor

            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="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);
        }
 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;
 }
        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())
 {
 }