Ejemplo n.º 1
0
        /// <summary>
        /// Edits the specified object's value using the editor style indicated by GetEditStyle.
        /// </summary>
        /// <param name="context">An ITypeDescriptorContext that can be used to gain additional context information.</param>
        /// <param name="provider">An IServiceProvider that this editor can use to obtain services.</param>
        /// <param name="value">The object to edit.</param>
        /// <returns></returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if ((context != null) && (context.Instance != null) && (provider != null))
            {
                // Convert to the correct class.
                MenuCommandCollection commands = value as MenuCommandCollection;

                // Create the dialog used to edit the menu commands
                MenuCollectionDialog dialog = new MenuCollectionDialog(commands);

                // Give user the chance to modify the nodes
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    // Reflect changes back into original copy and generate appropriate
                    // component changes to designer to reflect these changes
                    SynchronizeCollections(commands, dialog.Commands, context);

                    // Notify container that value has been changed
                    context.OnComponentChanged();

                    // Need to repaint the control to take account of new values
                    MenuControl mc = context.Instance as MenuControl;

                    // Just in case it is null
                    if (mc != null)
                    {
                        mc.Invalidate();
                    }
                }
            }

            // Return the original value
            return(value);
        }