반응형
        private Image Base64ToImage(string base64String)
        {
            // Convert Base64 String to byte[]
            byte[] imageBytes = Convert.FromBase64String(base64String);
            MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);

            // Convert byte[] to Image
            ms.Write(imageBytes, 0, imageBytes.Length);
            Image image = Image.FromStream(ms, true);
            return image;
        }
반응형
 

       private void MainForm_DragDrop(object sender, DragEventArgs e)
        {

            // transfer the filenames to a string array
            // (yes, everything to the left of the "=" can be put in the 
            // foreach loop in place of "files", but this is easier to understand.)
            if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
            {

                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

                foreach (string item in files)
                {
                    OpenFile(item);

                }
            }
        }





        private void MainForm_DragEnter(object sender, DragEventArgs e)
        {
            // make sure they're actually dropping files (not text or anything else)
            if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
                // allow them to continue
                // (without this, the cursor stays a "NO" symbol
                e.Effect = DragDropEffects.All;
        }
반응형
 public class EnumDescriptionTypeConverter : EnumConverter
    {
        public EnumDescriptionTypeConverter(Type type)
            : base(type)
        {
        }

        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return sourceType == typeof(string) || TypeDescriptor.GetConverter(typeof(Enum)).CanConvertFrom(context, sourceType);
        }

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
                return GetEnumValue(EnumType, (string)value);
            if (value is Enum)
                return GetEnumDescription((Enum)value);
            return base.ConvertFrom(context, culture, value);
        }

        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            return value is Enum && destinationType == typeof(string)
                ? GetEnumDescription((Enum)value)
                : (value is string && destinationType == typeof(string)
                  ? GetEnumDescription(EnumType, (string)value)
                  : base.ConvertTo(context, culture, value, destinationType));
        }

        public static string GetEnumDescription(Enum value)
        {
            var fieldInfo = value.GetType().GetField(value.ToString());
            var attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
            return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
        }

        public static string GetEnumDescription(Type value, string name)
        {
            var fieldInfo = value.GetField(name);
            var attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
            return (attributes.Length > 0) ? attributes[0].Description : name;
        }

        public static object GetEnumValue(Type value, string description)
        {
            var fields = value.GetFields();
            foreach (var fieldInfo in fields)
            {
                var attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
                if (attributes.Length > 0 && attributes[0].Description == description)
                    return fieldInfo.GetValue(fieldInfo.Name);
                if (fieldInfo.Name == description)
                    return fieldInfo.GetValue(fieldInfo.Name);
            }
            return description;
        }
       } 

[사용 방법]

public enum EVectorCharacter
{
  [Description("홍")]
  Hong,
}

'Programing > C# ' 카테고리의 다른 글

ColorComboBox 만들기  (0) 2012.06.21
Color이름으로 Color객체 얻어오기  (0) 2012.06.21
ComboBox in ListView (ListView에서 ComboBox띄우기)  (0) 2012.06.14
Convert Base64 To Image  (0) 2012.06.07
WindowForm에서 File DragAndDrop  (0) 2012.05.16

+ Recent posts