Click here to Skip to main content
12,635,428 members (23,801 online)
Click here to Skip to main content

Stats

126.1K views
4.4K downloads
120 bookmarked
Posted

Pretty IE Toolbar in C#

, 9 Sep 2008 CPOL
The article describes the work principles and ways of use of IEToolbarEngine. This is a toolbar for Internet Explorer, which has a reusable architecture.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Drawing;

namespace IEToolbarEngine
{
    /// <summary>
    /// Base class for IE toobar elements.
    /// </summary>
    internal abstract class BaseToolbarItem : IToolbarItem
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="engine">Toolbar engine</param>
        internal BaseToolbarItem ( IEToolbarEngine engine, System.Drawing.Image img )
        {
            this.image = img;
            this.engine = engine;
            items = new List<ToolStripItem> ();
        }

        protected IEToolbarEngine engine;
        protected List<ToolStripItem> items;

        #region IToolbarItem Members

        /// <summary>
        /// Visibility indicator
        /// </summary>
        public virtual bool Visible
        {
            get
            {                   
                if (engine == null || engine.Toolbar == null || engine.Toolbar.IsDisposed) return false;
                foreach (ToolStripItem item in items)
                {
                    if (item.Visible) return true;
                }

                return false;
            }
            set
            {
                if (engine == null || engine.Toolbar == null || engine.Toolbar.IsDisposed) return;
                foreach (ToolStripItem item in items)
                {
                    item.Visible = value;
                }
            }
        }

        /// <summary>
        /// Type identifier.
        /// </summary>
        public abstract ToolbarItemType TypeID
        {
            get;
        }

        virtual public Image Image
        {
            get
            {
                return image;
            }
            set
            {
                image = value;
            }
        }

        Image image = null;



        /// <summary>
        /// State cleanup
        /// </summary>
        public virtual void Reset ()
        {
            if (!(engine == null || engine.Toolbar == null || engine.Toolbar.IsDisposed))
            {
                foreach (ToolStripItem item in items)
                {
                    if (item.IsDisposed) continue;
                    engine.Toolbar.Items.Remove (item);
                    item.Dispose ();
                }
                items.Clear ();
            }
        }

        #endregion

        #region IDisposable Members

        bool disposed = false;
        // Implement IDisposable.
        // Do not make this method virtual.
        // A derived class should not be able to override this method.
        public void Dispose ()
        {
            Dispose(true);
            // This object will be cleaned up by the Dispose method.
            // Therefore, you should call GC.SupressFinalize to
            // take this object off the finalization queue 
            // and prevent finalization code for this object
            // from executing a second time.
            GC.SuppressFinalize(this);
        }

        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the 
        // runtime from inside the finalizer and you should not reference 
        // other objects. Only unmanaged resources can be disposed.
        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if(!this.disposed)
            {
                // If disposing equals true, dispose all managed 
                // and unmanaged resources.
                if(disposing)
                {
                // Dispose managed resources.
                    Reset ();
                }
    		 
                // Call the appropriate methods to clean up 
                // unmanaged resources here.
                // If disposing is false, 
                // only the following code is executed.
                //CloseHandle(handle);
                //handle = IntPtr.Zero;			
            }
            disposed = true;         
        }

        // Use C# destructor syntax for finalization code.
        // This destructor will run only if the Dispose method 
        // does not get called.
        // It gives your base class the opportunity to finalize.
        // Do not provide destructors in types derived from this class.
        ~BaseToolbarItem ()      
        {
            // Do not re-create Dispose clean-up code here.
            // Calling Dispose(false) is optimal in terms of
            // readability and maintainability.
            Dispose(false);
        }


        #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)

Share

About the Author

Alexandr Golovanov
Web Developer
Russian Federation Russian Federation
Alexandr Golovanov is a .NET developer at KB_Soft Group, an offshore software development company located in Russia, Novosibirsk. Here he has worked
on various .NET projects.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161208.2 | Last Updated 9 Sep 2008
Article Copyright 2008 by Alexandr Golovanov
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid