Click here to Skip to main content
15,888,008 members
Articles / Desktop Programming / Windows Forms

TreeTabControl. A Tree of Tab Items

Rate me:
Please Sign up or sign in to vote.
4.67/5 (11 votes)
28 Mar 2010CPOL5 min read 39K   3.4K   33  
Handling a tree of customized tab items
using System;
using System.Reflection;
using System.Collections;

namespace TreeTab
{
    public class DisposingMethod
    {
        #region Attributes

        private readonly ArrayList parameters;
        private readonly Delegate myDelegate;

        #endregion

        #region Properties

        /// <summary>
        /// Delegate for the method.
        /// </summary>
        public Delegate MyDelegate
        {
            get
            {
                return this.myDelegate;
            }
        }

        /// <summary>
        /// ArrayList containing the parameters for the method.
        /// </summary>
        public ArrayList Params
        {
            get
            {
                return this.parameters;
            }
        }

        /// <summary>
        /// Converts the collection of parameters to an array of objects.
        /// </summary>
        public object[] ParamsToArray
        {
            get
            {
                return this.parameters.ToArray();
            }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Overloads the contructor and sets the collection of parameters.
        /// </summary>
        /// <param name="_methodName">string</param>
        /// <param name="_target">object</param>
        /// <param name="_delegateType">Type</param>
        /// <param name="_parameters">ArrayList</param>
        public DisposingMethod(string _methodName, object _target, Type _delegateType, ArrayList _parameters)
            : this(_methodName, _target, _delegateType)
        {
            this.parameters = _parameters;
        }

        /// <summary>
        /// Tries to create the delegate for hte method.
        /// </summary>
        /// <param name="_methodName">string</param>
        /// <param name="_target">object</param>
        /// <param name="_delegateType">Type</param>
        public DisposingMethod(string _methodName, object _target, Type _delegateType)
        {
            try
            {
                this.myDelegate = Delegate.CreateDelegate(_delegateType, _target, _methodName);
            }
            catch (Exception ex)
            {
                throw new Exception("Error building the delegate:" + Environment.NewLine +
                    _methodName, ex);
            }
            this.parameters = new ArrayList();
        }

        #endregion

        #region Methods

        /// <summary>
        /// Executes the method.
        /// </summary>
        public void Execute()
        {
            try
            {
                this.MyDelegate.Method.Invoke(this.MyDelegate.Target, this.ParamsToArray);
            }
            catch(Exception ex)
            {
                throw new Exception("Error executing Disposing Method:" + Environment.NewLine +
                    this.MyDelegate.Method.Name, ex);
            }
        }

        #endregion
    }
}

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)


Written By
Software Developer (Senior)
Spain Spain
http://www.linkedin.com/in/gerard-castello-viader
https://github.com/gcastellov

Comments and Discussions