示例#1
0
 /// <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 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;
 }
示例#2
0
        /// <summary>
        /// Sets the controls to initial values.
        /// </summary>
        /// <param name="filler">The filler.</param>
        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;
            }
        }
示例#3
0
        /// <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="ArgumentNullException">filler</exception>
        /// <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);
        }
示例#4
0
 /// <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)
 {
 }
示例#5
0
 /// <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())
 {
 }
示例#6
0
 /// <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);
 }
示例#7
0
            // 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 BrushPainter)
                {
                    if (destinationType == typeof(string))
                    {
                        // Display string in designer
                        return("(BrushPainter)");
                    }
                    else if (destinationType == typeof(InstanceDescriptor))
                    {
                        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));
            }