How do you make your custom data types property browser browsable when contained in a Control/Component (as a property)
// Your custom data type public class MySize { … public int Width{get{…}set{…}} public int Height{get{…}set{…}} } public class MySizeConverter: ExpandableObjectConverter { public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) { return true; } public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues) { MySize size = new MySize(); size.Width = (int)propertyValues[(object)’Width’]; size.Height = (int)propertyValues[(object)’Height’]; return (object)size; }
How do you detect the designer host getting loaded for the first time in your designer
Subscribe to IDesignerHost.LoadComplete event. Make any changes to the designerhost (like adding/deleting component, etc.) only after this event, or else the design document will not be made ‘dirty’. (IdesignerSerializationManager.SerializationComplete will tell you when Code is deserialized into design time components).
When a property gets modified, how do you refresh other properties of a Component/Control in the property browser
Set this attribute for the property: RefreshProperties(RefreshProperties.Repaint)
How to HitTest a polygonal region
Bool HitTest(PointF[] polygonCorners, PointF mousePosition) { GraphicsPath path = new GraphicsPath(); path.AddLines(polygonCorners); Region region = new Region(path); // Hittest the region to verify if the point is in the rect if(region.IsVisible(mousePosition)) return true; else return false; }
How to add a Separator in a menu
contextmenu.MenuItems.Add(‘-‘);