public override void SetValue(object o, object value) { FunkyButton uc = o as FunkyButton; int delta = (int)value - uc.Points.Count; bool negative = delta < 0; delta = Math.Abs(delta); // we need to have at least 3 of these! // if ((int)value < 3) { throw new ArgumentException(); } // Walk through and add or remove vertices // as appropriate. // for (int i = 0; i < delta; i++) { if (!negative) { uc.Points.Add(new Point(0, 0)); } else { uc.Points.RemoveAt(uc.Points.Count - 1); } } }
/// <summary> /// When the value is set, we just push that value /// back up into the buttons Points array. /// </summary> public override void SetValue(object o, object value) { FunkyButton fb = o as FunkyButton; IComponentChangeService changeSvc = null; PropertyDescriptor prop = null; // Undo and code generation work off of the IComponentChangeService, so // we need to notify this service that we're making changes to the object. // Normally, when we set properties through a PropertyDescriptor this happens // automatically, but since we're modifying the collection directly, we // need to do this manually. // if (fb != null && fb.Site != null) { changeSvc = (IComponentChangeService)fb.Site.GetService(typeof(IComponentChangeService)); if (changeSvc != null) { // notify that we're changing the Points property // prop = TypeDescriptor.GetProperties(fb)["Points"]; try { changeSvc.OnComponentChanging(fb, prop); } catch (System.ComponentModel.Design.CheckoutException ex) { // if this exception was generated because the checkout of the file // was canceled by the user, just return silently. // if (ex == System.ComponentModel.Design.CheckoutException.Canceled) { return; } } } } // make the value change // fb.Points[index] = (Point)value; if (changeSvc != null) { // finally notify that the property value was actually changed. // changeSvc.OnComponentChanged(fb, prop, null, null); } }
/// <summary> /// Our main function. We display the vertices of a FunkyButton as properties by creating /// PropertyDescriptors for each one. /// </summary> /// <param name="context"></param> /// <param name="component"></param> /// <param name="attrs"></param> /// <returns></returns> public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs) { FunkyButton uc = component as FunkyButton; // we can get things besides FunkyButtons here. Since we want our Point types // to be expandable, the PropertyGrid will still ask this PropertyTab for the properties of // points, so we default to the standard way of getting properties from other types of objects. // if (uc == null) { TypeConverter tc = TypeDescriptor.GetConverter(component); if (tc != null) { return(tc.GetProperties(context, component, attrs)); } else { return(TypeDescriptor.GetProperties(component, attrs)); } } target = uc; // our list of props. // ArrayList propList = new ArrayList(); // add the property for our count of vertices // propList.Add(new NumPointsPropertyDescriptor(this)); // add a property descriptor for each vertex // for (int i = 0; i < ((FunkyButton)component).Points.Count; i++) { propList.Add(new VertexPropertyDescriptor(this, i)); } // return the collection of PropertyDescriptors. PropertyDescriptor[] props = (PropertyDescriptor[])propList.ToArray(typeof(PropertyDescriptor)); return(new PropertyDescriptorCollection(props)); }
/// <summary> /// Here, we hold our owning control and setup any initial /// values. /// </summary> /// <param name="owner"></param> /// <param name="initialValue"></param> internal PointsCollection(FunkyButton owner, Point[] initialValue) { AddRange(initialValue); this.owner = owner; }
public PointUIEditor(FunkyButton target) { // we use this to draw the paintvalue area. this.target = target; }