public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if ((destinationType != typeof(string)) || (value.GetType() != typeof(ColorValueRange)))
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }
            ColorValueRange range = (ColorValueRange)value;
            string          str   = string.Empty;
            int             num   = (int)((range.Minimum[0] * 255f) + 0.5f);
            int             num2  = (int)((range.Minimum[1] * 255f) + 0.5f);
            int             num3  = (int)((range.Minimum[2] * 255f) + 0.5f);
            int             num4  = (int)((range.Minimum[3] * 255f) + 0.5f);

            if (num4 != 255)
            {
                str = str + string.Format("{0} {1} {2} {3}", new object[] { num, num2, num3, num4 });
            }
            else
            {
                str = str + string.Format("{0} {1} {2}", num, num2, num3);
            }
            str  = str + "; ";
            num  = (int)((range.Maximum[0] * 255f) + 0.5f);
            num2 = (int)((range.Maximum[1] * 255f) + 0.5f);
            num3 = (int)((range.Maximum[2] * 255f) + 0.5f);
            num4 = (int)((range.Maximum[3] * 255f) + 0.5f);
            if (num4 != 255)
            {
                return(str + string.Format("{0} {1} {2} {3}", new object[] { num, num2, num3, num4 }));
            }
            return(str + string.Format("{0} {1} {2}", num, num2, num3));
        }
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     if (value.GetType() == typeof(string))
     {
         try
         {
             ColorValueRange range    = ColorValueRange.Parse((string)value);
             string[]        strArray = ((string)value).Split(new char[] { ';' });
             if (strArray[0].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Length == 3)
             {
                 range.Minimum *= new ColorValue(1f, 1f, 1f, 255f);
             }
             if (strArray[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Length == 3)
             {
                 range.Maximum *= new ColorValue(1f, 1f, 1f, 255f);
             }
             range.Minimum = range.Minimum / 255f;
             range.Maximum = range.Maximum / 255f;
             return(range);
         }
         catch (Exception)
         {
             return(value);
         }
     }
     return(base.ConvertFrom(context, culture, value));
 }
 public override void PaintValue(PaintValueEventArgs e)
 {
     if (e.Value != null)
     {
         ColorValueRange range = (ColorValueRange)e.Value;
         for (int i = 0; i < 2; i++)
         {
             Rectangle  rectangle;
             ColorValue value2 = range[i];
             if (i == 0)
             {
                 rectangle = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Size.Width / 2, e.Bounds.Size.Height);
             }
             else
             {
                 rectangle = new Rectangle(e.Bounds.X + (e.Bounds.Size.Width / 2), e.Bounds.Y, e.Bounds.Size.Width / 2, e.Bounds.Size.Height);
             }
             int[] numArray = new int[4];
             for (int j = 0; j < 4; j++)
             {
                 int num3 = (int)(value2[j] * 255f);
                 if (num3 < 0)
                 {
                     num3 = 0;
                 }
                 if (num3 > 255)
                 {
                     num3 = 255;
                 }
                 numArray[j] = num3;
             }
             if (value2.Alpha != 1f)
             {
                 using (HatchBrush brush = new HatchBrush(HatchStyle.LargeCheckerBoard, Color.FromArgb(128, 128, 128), Color.FromArgb(192, 192, 192)))
                 {
                     e.Graphics.FillRectangle(brush, rectangle);
                 }
             }
             Color color  = Color.FromArgb(255, numArray[0], numArray[1], numArray[2]);
             Color color2 = Color.FromArgb(numArray[3], numArray[0], numArray[1], numArray[2]);
             using (LinearGradientBrush brush2 = new LinearGradientBrush(rectangle, color, color2, 90f, false))
             {
                 e.Graphics.FillRectangle(brush2, rectangle);
             }
         }
     }
     base.PaintValue(e);
 }
        public static ColorValueRange Parse(string text)
        {
            ColorValueRange range;

            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("The parsableText parameter cannot be null or zero length.");
            }
            string[] strArray = text.Split(new char[] { ';' });
            if (strArray.Length != 2)
            {
                throw new FormatException(string.Format("Cannot parse the text '{0}' because it does not have 2 parts separated by \";\" in the form (0 1) with optional parenthesis.", text));
            }
            try
            {
                range = new ColorValueRange(ColorValue.Parse(strArray[0].Trim()), ColorValue.Parse(strArray[1].Trim()));
            }
            catch (Exception)
            {
                throw new FormatException("The parts of the colors must be decimal numbers.");
            }
            return(range);
        }
Beispiel #5
0
 public abstract void ColorValueRangeEditorControlShow(IServiceProvider provider, object[] propertyOwners, PropertyInfo property, out bool changed, out ColorValueRange newValue);
Beispiel #6
0
 public abstract void ColorValueRangeEditorControlShow(IServiceProvider provider, ColorValueRange colorValueRange, out bool changed, out ColorValueRange newValue);
 static ColorValueRange()
 {
     Zero  = new ColorValueRange(ColorValue.Zero, ColorValue.Zero);
     White = new ColorValueRange(new ColorValue(1f, 1f, 1f), new ColorValue(1f, 1f, 1f));
 }
 public ColorValueRange(ColorValueRange source)
 {
     minimum = source.minimum;
     maximum = source.maximum;
 }