Click here to Skip to main content
11,634,634 members (69,567 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
Add your own
alternative version

A Simple Wizard Control for .Net 2.0 with Full Designer Support

, 4 Feb 2008 CPOL 365K 11.4K 378
This is a simple yet powerful wizard framework for .Net 2.0. Just drag and drop and your component is ready for use.
wizardbase_demo.zip
WizardBase.dll
WizardDemo.exe
wizarddemo_demo.zip
WizardDemo.exe
WizardBase.dll
wizarddemo_lib.zip
WizardBase.dll
wizarddemo_src.zip
WizardDemo
WizardBase
Collection
vssver2.scc
Converters
vssver2.scc
Designers
vssver2.scc
EventArgs
vssver2.scc
Properties
vssver2.scc
Resources
back.png
icon.png
left.png
Top.png
vssver2.scc
Steps
vssver2.scc
Structures
vssver2.scc
WizardDemo
Properties
licenses.licx
Settings.settings
vssver2.scc
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Drawing.Design;
using System.Globalization;

namespace WizardBase
{
    [Editor(typeof(CollectionEditor), typeof(UITypeEditor))]
    internal class GenericCollectionConverter<T> : TypeConverter
    {
        ///<summary>
        ///Returns whether this converter can convert an object of the given type to the type of this converter, using the specified context.
        ///</summary>
        ///
        ///<returns>
        ///true if this converter can perform the conversion; otherwise, false.
        ///</returns>
        ///
        ///<param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        ///<param name="sourceType">A <see cref="T:System.Type"></see> that represents the type you want to convert from. </param>
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType));
        }

        ///<summary>
        ///Returns whether this converter can convert the object to the specified type, using the specified context.
        ///</summary>
        ///
        ///<returns>
        ///true if this converter can perform the conversion; otherwise, false.
        ///</returns>
        ///
        ///<param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        ///<param name="destinationType">A <see cref="T:System.Type"></see> that represents the type you want to convert to. </param>
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            return ((destinationType == typeof(InstanceDescriptor)) || base.CanConvertTo(context, destinationType));
        }

        ///<summary>
        ///Converts the given value object to the specified type, using the specified context and culture information.
        ///</summary>
        ///
        ///<returns>
        ///An <see cref="T:System.Object"></see> that represents the converted value.
        ///</returns>
        ///
        ///<param name="culture">A <see cref="T:System.Globalization.CultureInfo"></see>. If null is passed, the current culture is assumed. </param>
        ///<param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        ///<param name="destinationType">The <see cref="T:System.Type"></see> to convert the value parameter to. </param>
        ///<param name="value">The <see cref="T:System.Object"></see> to convert. </param>
        ///<exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        ///<exception cref="T:System.ArgumentNullException">The destinationType parameter is null. </exception>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }
            if (value is GenericCollection<T>)
            {
                return "(Items)";
            }
            if (value is CollectionBase)
            {
                return "(Items)";
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }

        ///<summary>
        ///Returns whether this object supports properties, using the specified context.
        ///</summary>
        ///
        ///<returns>
        ///true if <see cref="M:System.ComponentModel.TypeConverter.GetProperties(System.Object)"></see> should be called to find the properties of this object; otherwise, false.
        ///</returns>
        ///
        ///<param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        public override bool GetPropertiesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        ///<summary>
        ///Returns whether changing a value on this object requires a call to <see cref="M:System.ComponentModel.TypeConverter.CreateInstance(System.Collections.IDictionary)"></see> to create a new value, using the specified context.
        ///</summary>
        ///
        ///<returns>
        ///true if changing a property on this object requires a call to <see cref="M:System.ComponentModel.TypeConverter.CreateInstance(System.Collections.IDictionary)"></see> to create a new value; otherwise, false.
        ///</returns>
        ///
        ///<param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        public override bool GetCreateInstanceSupported(ITypeDescriptorContext context)
        {
            return false;
        }

        ///<summary>
        ///Returns a collection of properties for the type of array specified by the value parameter, using the specified context and attributes.
        ///</summary>
        ///
        ///<returns>
        ///A <see cref="T:System.ComponentModel.PropertyDescriptorCollection"></see> with the properties that are exposed for this data type, or null if there are no properties.
        ///</returns>
        ///
        ///<param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        ///<param name="attributes">An array of type <see cref="T:System.Attribute"></see> that is used as a filter. </param>
        ///<param name="value">An <see cref="T:System.Object"></see> that specifies the type of array for which to get properties. </param>
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            GenericCollection<T> collection = value as GenericCollection<T>;
            if (collection != null)
            {
                PropertyDescriptor[] properties = new PropertyDescriptor[collection.Count];
                for (int i = 0; i < collection.Count; i++)
                {
                    try
                    {
                        properties[i] = (new PDesc<T>(collection[i]));
                    }
#pragma warning disable EmptyGeneralCatchClause
                    catch (Exception)
#pragma warning restore EmptyGeneralCatchClause
                    {
                    }
                }
                return new PropertyDescriptorCollection(properties);
            }
            return base.GetProperties(context, value, attributes);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Manish Ranjan Kumar
Software Developer (Senior)
India India
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150728.1 | Last Updated 4 Feb 2008
Article Copyright 2007 by Manish Ranjan Kumar
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid