Common SimpleTask
Common_SimpleTask_CSharpSimpleTask_CSharp\ButtonTextEditor.cs
// Copyright 2007 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.ComponentModel;
using System.Windows.Forms.Design;
using System.Collections;

namespace SimpleTask_CSharp
{
    /// <summary>
    /// Edits ButtonText property on a SimpleTask.
    /// </summary>
    public class ButtonTextEditor : UITypeEditor
    {
        /// <summary>
        /// Edits the value of the specified object using the editor style indicated by GetEditStyle.
        /// </summary>
        /// <param name="context">An ITypeDescriptorContext that can be used to gain additional context information<see cref="System.ComponentModel.ITypeDescriptorContext"/></param>
        /// <param name="provider">An IServiceProvider that this editor can use to obtain services</param>
        /// <param name="value">The object to edit</param>
        /// <returns>The edited value.</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if ((context != null) && (provider != null))
            {
                System.Web.UI.Control ctrl = context.Instance as System.Web.UI.Control;

                if (ctrl == null)
                    return value;

                ButtonTextEditorForm form = new ButtonTextEditorForm(value as string);
                if (form.ShowDialog() == DialogResult.OK)
                    value = form.Value;
            }
            return value;
        }

        /// <summary>
        /// Gets the editor style used by the EditValue method
        /// </summary>
        /// <param name="context">An ITypeDescriptorContext that can be used to gain additional context information<see cref="System.ComponentModel.ITypeDescriptorContext"/></param>
        /// <returns>If the context is not null, the Style will always be returned as Modal, otherwise will return a default edit style</returns>
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            if (context != null)
            {
                return UITypeEditorEditStyle.Modal;
            }
            return base.GetEditStyle(context);
        }
    }
}