Exemplo n.º 1
0
        /// <summary>Launches the design-time editor for the property of the component behind a designer.</summary>
        /// <param name="designer">The designer for a component.</param>
        /// <param name="propName">The name of the property to edit. If this value is null, the default property for the object is used.</param>
        /// <param name="objectToChange">The object on which to edit the property. If this value is null, the Component property of the designer is used.</param>
        /// <returns>The new value returned by the editor.</returns>
        public static object EditValue(this ComponentDesigner designer, string propName, object objectToChange = null)
        {
            if (objectToChange == null)
            {
                objectToChange = designer.Component;
            }
            var prop = (propName == null) ? TypeDescriptor.GetDefaultProperty(objectToChange) : TypeDescriptor.GetProperties(objectToChange)[propName];

            if (prop == null)
            {
                throw new ArgumentException("Unable to retrieve specified property.");
            }
            var context = new EditorServiceContext(designer, prop);
            var editor  = prop.GetEditor(typeof(UITypeEditor)) as UITypeEditor;
            var curVal  = prop.GetValue(objectToChange);
            var newVal  = editor?.EditValue(context, context, curVal);

            if (newVal != curVal)
            {
                try { prop.SetValue(objectToChange, newVal); }
                catch (CheckoutException) { }
            }
            return(newVal);
        }
Exemplo n.º 2
0
        /// <summary>Shows a form tied to a designer.</summary>
        /// <param name="designer">The designer for a component.</param>
        /// <param name="dialog">A form instance.</param>
        /// <returns>The result of calling ShowDialog on the form.</returns>
        public static DialogResult ShowDialog(this ComponentDesigner designer, Form dialog)
        {
            var context = new EditorServiceContext(designer);

            return(context.ShowDialog(dialog));
        }