private GradientFill FromString(object value)
        {
            string[] values = ((string)value).Split(',');
            if (values.Length != 3)
            {
                throw new ArgumentException("Could not convert the value");
            }

            try
            {
                GradientFill gradient = new GradientFill();

                ColorConverter converter = new ColorConverter();

                gradient.ColorA = (Color)converter.ConvertFromString(values[0]);
                gradient.ColorB = (Color)converter.ConvertFromString(values[1]);

                // Convert the name of the enumerated value into the corresponding
                // enumerated value (which is actually an integer constant).
                gradient.GradientFillStyle = (LinearGradientMode)Enum.Parse(
                    typeof(LinearGradientMode), values[2], true);

                return(gradient);
            }
            catch
            {
                throw new ArgumentException("Could not convert the value");
            }
        }
コード例 #2
0
        private GradientFill FromString(object value)
        {
            string[] values = ((string)value).Split(',');
            if (values.Length != 3)
                throw new ArgumentException("Could not convert the value");

            try
            {
                GradientFill gradient = new GradientFill();

                ColorConverter converter = new ColorConverter();
                
                gradient.ColorA = (Color)converter.ConvertFromString(values[0]);
                gradient.ColorB = (Color)converter.ConvertFromString(values[1]);

                // Convert the name of the enumerated value into the corresponding
                // enumerated value (which is actually an integer constant).
                gradient.GradientFillStyle = (LinearGradientMode)Enum.Parse(
                  typeof(LinearGradientMode), values[2], true);

                return gradient;
            }
            catch
            {
                throw new ArgumentException("Could not convert the value");
            }
        }
        private string ToString(object value)
        {
            GradientFill   fill      = (GradientFill)value;
            ColorConverter converter = new ColorConverter();

            return(String.Format("{0}, {1}, {2}", converter.ConvertToString(fill.ColorA), converter.ConvertToString(fill.ColorB), fill.GradientFillStyle.ToString()));
        }
コード例 #4
0
        public override void PaintValue(
            System.Drawing.Design.PaintValueEventArgs e)
        {
            GradientFill        fill  = (GradientFill)e.Value;
            LinearGradientBrush brush = new LinearGradientBrush(e.Bounds,
                                                                fill.ColorA, fill.ColorB, fill.GradientFillStyle);

            // Paint the thumbnail.
            e.Graphics.FillRectangle(brush, e.Bounds);
        }