Ejemplo n.º 1
0
 protected override bool ProcessDialogKey(Keys keyData)
 {
     if (keyData == Keys.Escape)
     {
         m_old_hobbies = m_new_hobbies;
         canceling     = true;
     }
     return(base.ProcessDialogKey(keyData));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 使用指定的上下文和区域性信息将给定值对象转换为指定的类型。
        /// </summary>
        /// <param name="context">一个 System.ComponentModel.ITypeDescriptorContext,用于提供格式上下文。</param>
        /// <param name="culture">System.Globalization.CultureInfo。 如果传递 null,则采用当前区域性。</param>
        /// <param name="value">要转换的 System.Object。</param>
        /// <param name="destinationType">System.Type 转换 value 参数</param>
        /// <returns>一个 System.Object,它表示转换后的值。</returns>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            StringBuilder sb = new StringBuilder();

            if (value == null)
            {
                return("");
            }
            if (destinationType == typeof(string))
            {
                Hobbies hobbies = value as Hobbies;
                if (hobbies.Music)
                {
                    sb.Append("Music,");
                }
                if (hobbies.Game)
                {
                    sb.Append("Game,");
                }
                if (hobbies.Running)
                {
                    sb.Append("Running,");
                }
                if (hobbies.Film)
                {
                    sb.Append("Film,");
                }
                if (hobbies.Basketball)
                {
                    sb.Append("Basketball,");
                }

                if (sb.Length > 0)
                {
                    return(sb.ToString().Substring(0, sb.ToString().Length - 1));
                }
                else
                {
                    return("");
                }
            }

            if (destinationType == typeof(InstanceDescriptor) && value != null)
            {
                ConstructorInfo constructorInfo = typeof(Hobbies).GetConstructor(new Type[] {});
                Hobbies         point           = value as Hobbies;
                return(new InstanceDescriptor(constructorInfo, new object[] {  }));
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
Ejemplo n.º 3
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                Hobbies  hobbies = new Hobbies();
                string[] par     = value.ToString().Split(',');
                if (par.Length == 0)
                {
                    throw new NotSupportedException("输入非法");
                }
                foreach (var item in par)
                {
                    switch (item)
                    {
                    case "Music":
                        hobbies.Music = true;
                        break;

                    case "Game":
                        hobbies.Game = true;
                        break;

                    case "Running":
                        hobbies.Running = true;
                        break;

                    case "Film":
                        hobbies.Film = true;
                        break;

                    case "Basketball":
                        hobbies.Basketball = true;
                        break;

                    default:
                        break;
                    }
                }
                return(hobbies);
            }

            return(base.ConvertFrom(context, culture, value));
        }
Ejemplo n.º 4
0
 public HobbiesCtrl(Hobbies hobbies)
 {
     InitializeComponent();
     m_old_hobbies = hobbies;
     m_new_hobbies = hobbies;
 }