/// <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, System.Type destinationType) { if (destinationType == null) { //MessageBox.Show("Erreur ! destinationType"); throw new ArgumentNullException("destinationType"); } if (value == null) { return(string.Empty); } if ((destinationType == typeof(GeniusPen)) && (value is GeniusPen)) { return(value); } if ((destinationType == typeof(string)) && (value is GeniusPen)) { GeniusPen br = (GeniusPen)value; if (culture == null) { culture = CultureInfo.CurrentCulture; } TypeConverter floatConverter = TypeDescriptor.GetConverter(typeof(float)); TypeConverter colorConverter = TypeDescriptor.GetConverter(typeof(Color)); TypeConverter DashConverter = TypeDescriptor.GetConverter(typeof(DashStyle)); string text1 = culture.TextInfo.ListSeparator + " "; string[] properties = new string[3]; int index = 0; properties[index++] = floatConverter.ConvertToString(context, culture, br.Width); properties[index++] = colorConverter.ConvertToString(context, culture, br.Color); properties[index++] = DashConverter.ConvertToString(context, culture, br.Style); return(string.Join(text1, properties)); } if ((destinationType != typeof(InstanceDescriptor)) || !(value is GeniusPen)) { return(base.CanConvertTo(context, destinationType)); } Type[] array = new Type[] { typeof(Color), typeof(float), typeof(DashStyle) }; ConstructorInfo constructor = typeof(GeniusPen).GetConstructor(array); if (constructor != null) { GeniusPen pen = (GeniusPen)value; object[] objArray = new object[] { pen.Color, pen.Width, pen.Style }; return(new InstanceDescriptor(constructor, objArray)); } return(base.CanConvertTo(context, destinationType)); }
private void button1_Click(object sender, System.EventArgs e) { GeniusPen pen = new GeniusPen(Color.FromArgb(192, 192, 184), 1, DashStyle.Dot); geniusTreeView1.Colors.FocusedRectanglePenColor = pen; TypeConverter cnv = TypeDescriptor.GetConverter(typeof(GeniusPen)); string str = cnv.ConvertToString(pen); textBox1.AppendText(Environment.NewLine); textBox1.AppendText(str); textBox1.AppendText(Environment.NewLine); GeniusPen pen1 = (GeniusPen)cnv.ConvertFrom(str); str = cnv.ConvertToString(pen1); textBox1.AppendText(str); str = cnv.ConvertToString(geniusTreeView1.Colors.FocusedRectanglePenColor); textBox1.AppendText(str); }
private GeniusPen PenToGeniusPen(Pen pen) { GeniusPen Result = new GeniusPen(pen.Color, pen.Width, pen.DashStyle); return(Result); }