Ejemplo n.º 1
0
        /// <summary>
        /// Initializes and draws the template editor dialog and returns the results to the calling object.
        /// </summary>
        /// <param name="context">See <see cref="UITypeEditor.EditValue"/>.</param>
        /// <param name="provider">See <see cref="UITypeEditor.EditValue"/>.</param>
        /// <param name="value">See <see cref="UITypeEditor.EditValue"/>.</param>
        /// <returns>See <see cref="UITypeEditor.EditValue"/>.</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Debug.Assert(provider != null, "No service provider; we cannot edit the value");
            if (provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

                Debug.Assert(edSvc != null, "No editor service; we cannot edit the value");
                if (edSvc != null)
                {
                    IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

                    TemplateEditorUI dialog = new TemplateEditorUI();

                    string originalText = ((Template)value).Text;
                    dialog.UserText = originalText;

                    DialogResult dialogResult = service.ShowDialog(dialog);

                    if (dialogResult == DialogResult.Cancel)
                    {
                        return(new Template(originalText));
                    }

                    return(new Template(dialog.UserText));
                }
            }
            return(value);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes and draws the template editor dialog and returns the results to the calling object.
        /// </summary>
        /// <param name="context">See <see cref="UITypeEditor.EditValue"/>.</param>
        /// <param name="provider">See <see cref="UITypeEditor.EditValue"/>.</param>
        /// <param name="value">See <see cref="UITypeEditor.EditValue"/>.</param>
        /// <returns>See <see cref="UITypeEditor.EditValue"/>.</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Debug.Assert(provider != null, "No service provider; we cannot edit the value");
            if (provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

                Debug.Assert(edSvc != null, "No editor service; we cannot edit the value");
                if (edSvc != null)
                {
                    IWindowsFormsEditorService service = (IWindowsFormsEditorService) provider.GetService(typeof(IWindowsFormsEditorService));

                    TemplateEditorUI dialog = new TemplateEditorUI();

                    string originalText = ((Template)value).Text;
                    dialog.UserText = originalText;

                    DialogResult dialogResult = service.ShowDialog(dialog);

                    if (dialogResult == DialogResult.Cancel)
                    {
                        return new Template(originalText);
                    }

                    return new Template(dialog.UserText);
                }
            }
            return value;
        }