Common Simple Server task
Common_SimpleServerTask_CSharp\ButtonTextEditor.cs
// Copyright 2011 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.
// 

namespace SimpleServerTask_CSharp
{
    /// <summary>
    /// Edits ButtonText property on a SimpleTask.
    /// </summary>
    public class ButtonTextEditor : System.Drawing.Design.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(System.ComponentModel.ITypeDescriptorContext typeDescriptorContext, 
            System.IServiceProvider serviceProvider, object value)
        {
            // Make sure a valid type descriptor context and service provider were passed in
            if ((typeDescriptorContext != null) && (serviceProvider != null))
            {
                // If the type descriptor context's instance (the control - in this case a simple task -
                // being configured) is null, exit the method without updating any properties
                if (typeDescriptorContext.Instance == null)
                    return value;

                // Instantiate the form to edit the simple task's button text
                ButtonTextEditorForm buttonTextEditorForm = new ButtonTextEditorForm(value as string);

                // Show the form.  If the form closes by the user clicking OK, then update the button
                // text with that specified on the form.
                if (buttonTextEditorForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    value = buttonTextEditorForm.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 System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(
            System.ComponentModel.ITypeDescriptorContext typeDescriptorContext)
        {
            if (typeDescriptorContext != null)
            {
                return System.Drawing.Design.UITypeEditorEditStyle.Modal;
            }
            return base.GetEditStyle(typeDescriptorContext);
        }
    }
}