//下面两个函数是为了在PropertyGrid中显示一个辅助的效果 //可以不用重写 public override void PaintValue(System.Drawing.Design.PaintValueEventArgs e) { List <Color> cl = e.Value as List <Color>; if (cl == null) { ColorProp cp = e.Value as ColorProp; cl = cp.colorList; } int normalX = (e.Bounds.Width / 2); int normalY = (e.Bounds.Height / 2); int curY = e.Bounds.Y; for (int i = 0; i < cl.Count; i++) { e.Graphics.FillRectangle(new SolidBrush(cl[i]), e.Bounds.X + (i * 10), e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); } e.Graphics.FillEllipse(new SolidBrush(Color.White), e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 3, e.Bounds.Height - 3); e.Graphics.FillEllipse(new SolidBrush(Color.SlateGray), normalX + e.Bounds.X - 1, normalY + e.Bounds.Y - 1, 3, 3); double radians = 5; e.Graphics.DrawLine(new Pen(new SolidBrush(Color.Red), 1), normalX + e.Bounds.X, normalY + e.Bounds.Y, e.Bounds.X + (normalX + (int)((double)normalX * Math.Cos(radians))), e.Bounds.Y + (normalY + (int)((double)normalY * Math.Sin(radians)))); }
public override object ConvertTo( ITypeDescriptorContext context, CultureInfo culture, object value, Type destType) { if (destType == typeof(string) && value is ColorProp) { ColorProp p = (ColorProp)value; // simply build the string as "Last, First (Age)" Button b = new Button(); b.Text = "aaaa"; return(p); } return(base.ConvertTo(context, culture, value, destType)); }
public TCSettings() { Scale = new ScaleProp(); FaceColorList2 = new ColorProp(); /*FaceColorList2.colorList = new List<Color>{ * Color.FromArgb(255,0,0), * Color.FromArgb(126,0,0), * Color.FromArgb(0,126,0), * Color.FromArgb(0,255,0), * Color.FromArgb(0,0,125), * Color.FromArgb(0,0,255) * };*/ FaceColorList2.colorList = ColorizeBase.genColorList(colorCount); ContourFont = new Font(FontFamily.GenericSerif, 11); }
public override object ConvertFrom( ITypeDescriptorContext context, CultureInfo info, object value) { if (value is string) { try { string s = (string)value; // parse the format "Last, First (Age)" // int comma = s.IndexOf(','); if (comma != -1) { // now that we have the comma, get // the last name. string last = s.Substring(0, comma); int paren = s.LastIndexOf('('); if (paren != -1 && s.LastIndexOf(')') == s.Length - 1) { // pick up the first name string first = s.Substring(comma + 1, paren - comma - 1); // get the age int age = Int32.Parse( s.Substring(paren + 1, s.Length - paren - 2)); ColorProp p = new ColorProp(); return(p); } } } catch {} // if we got this far, complain that we // couldn't parse the string // throw new ArgumentException( "Can not convert '" + (string)value + "' to type Person"); } return(base.ConvertFrom(context, info, value)); }
//下面两个函数是为了在PropertyGrid中显示一个辅助的效果 //可以不用重写 public override void PaintValue(System.Drawing.Design.PaintValueEventArgs e) { List <Color> cl = e.Value as List <Color>; if (cl == null) { ColorProp cp = e.Value as ColorProp; cl = cp.colorList; } int normalX = (e.Bounds.Width / 2); int normalY = (e.Bounds.Height / 2); int curY = e.Bounds.Y; for (int i = 0; i < cl.Count; i++) { e.Graphics.FillRectangle(new SolidBrush(cl[i]), e.Bounds.X + (i * 10), e.Bounds.Y, 10, e.Bounds.Height); } }
public ColorPropControl(ColorProp cl) { CP = cl; InitializeComponent(); }