Example #1
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 Filler2)
                {
                    if (destinationType == typeof(string))
                    {
                        // Display string in designer
                        return("(Filler2)");
                    }
                    else if (destinationType == typeof(InstanceDescriptor))
                    {
                        Filler2 filler = (Filler2)value;

                        if (filler.FillType == Filler2Type.Solid)
                        {
                            ConstructorInfo ctor = typeof(Filler2).GetConstructor(new Type[] { typeof(Color) });
                            if (ctor != null)
                            {
                                return(new InstanceDescriptor(ctor, new object[] { filler.SolidColor }));
                            }
                        }
                        else if (filler.FillType == Filler2Type.Hatch)
                        {
                            ConstructorInfo ctor = typeof(Filler2).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 == Filler2Type.Gradient)
                        {
                            ConstructorInfo ctor = typeof(Filler2).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(Filler2).GetConstructor(Type.EmptyTypes);
                            if (ctor != null)
                            {
                                return(new InstanceDescriptor(ctor, null));
                            }
                        }
                    }
                }
                return(base.ConvertTo(context, culture, value, destinationType));
            }
Example #2
0
        /// <summary>
        /// Initializes a new instance of <c>Filler2EditorDialog</c> using an existing <c>Filler2</c>
        /// at the default window position.
        /// </summary>
        /// <param name="filler">Existing <c>Filler2</c> object.</param>
        /// <exception cref="ArgumentNullException">filler</exception>
        /// <exception cref="System.ArgumentNullException">Thrown if <paramref name="filler" /> is null.</exception>
        public Filler2EditorDialog(Filler2 filler)
        {
            if (filler == null)
            {
                throw new ArgumentNullException("filler");
            }

            InitializeComponent();
            AdjustDialogSize();
            SetControlsToInitialValues(filler);
        }
Example #3
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 Filler2(FromLabelNud(solidColorLabel, solidAlphaNud));
     }
     else if (hatchRadioButton.Checked)
     {
         filler = new Filler2(hatchComboBox.SelectedHatchStyle,
                              FromLabelNud(hatchColorLabel, hatchAlphaNud),
                              FromLabelNud(backColorLabel, backAlphaNud));
     }
     else if (gradientRadioButton.Checked)
     {
         filler = new Filler2(gradientEditor.Blend);
     }
     else
     {
         filler = Filler2.Empty();
     }
     DialogResult = DialogResult.OK;
 }
Example #4
0
        /// <summary>
        /// Sets the controls to initial values.
        /// </summary>
        /// <param name="filler">The filler.</param>
        private void SetControlsToInitialValues(Filler2 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 == Filler2Type.None)
            {
                noneRadioButton.Checked = true;
            }
            else if (filler.FillType == Filler2Type.Solid)
            {
                solidRadioButton.Checked = true;
            }
            else if (filler.FillType == Filler2Type.Hatch)
            {
                hatchRadioButton.Checked = true;
            }
            else
            {
                gradientRadioButton.Checked = true;
            }
        }
Example #5
0
 /// <summary>
 /// Initializes a new instance of <c>Filler2EditorDialog</c> using an existing <c>Filler2</c>
 /// and positioned beneath the specified control.
 /// </summary>
 /// <param name="filler">Existing <c>Filler2</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 Filler2EditorDialog(Filler2 filler, Control c) : this(filler)
 {
     Utils.SetStartPositionBelowControl(this, c);
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of <c>Filler2EditorDialog</c> using an empty <c>Filler2</c>
 /// and positioned beneath the specified control.
 /// </summary>
 /// <param name="c">Control beneath which the dialog should be placed.</param>
 public Filler2EditorDialog(Control c) : this(Filler2.Empty(), c)
 {
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of <c>Filler2EditorDialog</c> using an empty <c>Filler2</c>
 /// at the default window position.
 /// </summary>
 public Filler2EditorDialog() : this(Filler2.Empty())
 {
 }