Example #1
0
 public Icon(Stream stream, string fileName)
 {
     byte[] bs = new byte[(uint)stream.Length];
     stream.Read(bs, 0, (int)stream.Length);
     _image = Image.FromStream(new MemoryStream(bs));
     _size  = _image.Size;
     _file  = fileName;
 }
Example #2
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType)
        {
            if (value != null)
            {
                if (!(value is SizeIcon))
                {
                    throw new ArgumentException("Invalid SizeIcon", "value");
                }
            }

            if (destinationType == typeof(System.String))
            {
                if (value == null)
                {
                    return(String.Empty);
                }

                SizeIcon sizeIcon = (SizeIcon)value;

                TypeConverter intConverter =
                    TypeDescriptor.GetConverter(typeof(Int32));
                return(String.Join(culture.TextInfo.ListSeparator, new String[] {
                    intConverter.ConvertToString(context, culture, sizeIcon.Width),
                    intConverter.ConvertToString(context, culture, sizeIcon.Heigth)
                }
                                   ));
            }

            else if (destinationType == typeof(InstanceDescriptor))
            {
                if (value == null)
                {
                    return(null);
                }

                MemberInfo mi   = null;
                object[]   args = null;

                SizeIcon sizeIcon = (SizeIcon)value;

                Type intType = typeof(int);
                mi   = typeof(SizeIcon).GetConstructor(new Type[] { intType, intType });
                args = new object[] { sizeIcon.Width, sizeIcon.Heigth };

                if (mi != null)
                {
                    return(new InstanceDescriptor(mi, args));
                }
                else
                {
                    return(null);
                }
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Example #3
0
 public Icon()
 {
     _image = new Bitmap(16, 16);
     _size  = _image.Size;
 }