示例#1
0
        /// <summary>
        /// 返回表示对象的字符串
        /// </summary>
        /// <returns>字符串</returns>
        public override string ToString()
        {
            if (intStyle == XBrushStyleConst.Disabled)
            {
                return("Disabled");
            }

            if (myImage != null && myImage.Value != null)
            {
                string str = "";
                if (bolRepeat)
                {
                    str = " Repeat ";
                }
                str = str + myImage.ToString();
                return(str);
            }
            else if (intStyle == XBrushStyleConst.Solid)
            {
                return(ColorTranslator.ToHtml(intColor));
            }
            else
            {
                return(intStyle.ToString()
                       + " " + System.Drawing.ColorTranslator.ToHtml(intColor)
                       + "->" + System.Drawing.ColorTranslator.ToHtml(intColor2));
            }
        }
示例#2
0
        /// <summary>
        /// 将图片转换为指定类型的数据
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="culture">区域信息</param>
        /// <param name="Value">图片数据</param>
        /// <param name="destinationType">指定的类型</param>
        /// <returns>转换结果</returns>
        public override object ConvertTo(
            ITypeDescriptorContext context,
            System.Globalization.CultureInfo culture,
            object Value,
            Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }

            XImageValue img = ( XImageValue )Value;

            if (img == null)
            {
                return("[NULL]");
            }
            if (destinationType == typeof(string))
            {
                return(img.ToString());
            }

            if (destinationType == typeof(byte[]))
            {
                return(img.ImageData);
            }

            if (destinationType == typeof(InstanceDescriptor))
            {
                byte[] bs = img.ImageData;
                if (bs == null || bs.Length == 0)
                {
                    return(new InstanceDescriptor(typeof(XImageValue).GetConstructor(
                                                      new Type[] {}),
                                                  new object[] {}));
                }
                else
                {
                    System.Reflection.MemberInfo constructor = typeof(XImageValue).GetConstructor(new Type[] { typeof(byte[]) });
                    return(new InstanceDescriptor(constructor, new object[] { img.ImageData }));
                }
            }

            return(base.ConvertTo(context, culture, Value, destinationType));
        }