Click here to Skip to main content
15,896,730 members
Articles / Programming Languages / C#

Extended Interface for Toolbars

Rate me:
Please Sign up or sign in to vote.
4.88/5 (27 votes)
10 Apr 20023 min read 193.4K   388   87  
This extension allows toolbar buttons to call functions automatically
using System;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace ExtendedInterface
{
///<summary>
/// Extended Interface to allow status messages from a menu item to appear in the status bar automatically
///</summary>

   [ProvideProperty( "StatusMessage", typeof(Component)) ]
   public class StatusMessage : Component, IExtenderProvider 
   {
      Hashtable m_Dictionary = new Hashtable( );

      ///<summary>
      /// Assign the message that will appear in the StatusBarPanel when a MenuItem is selected
      ///</summary>

      public void SetStatusMessage( Component pComponent, string strMessage )
      {
         if( ! m_Dictionary.Contains( pComponent ))
         {
            m_Dictionary.Add( pComponent, strMessage );

            MenuItem pMenuItem = pComponent as MenuItem;

            if( pMenuItem != null )
               pMenuItem.Select += new EventHandler( Handle_MenuSelect );
         }
         else 
         {
            m_Dictionary[ pComponent ] = strMessage;
         }
      }

      ///<summary>
      /// Retrieve the message that will appear in the StatusBarPanel when a MenuItem is selected
      ///</summary>

      public string GetStatusMessage( Component pComponent )
      {
         if( m_Dictionary.Contains( pComponent ))
            return (string) m_Dictionary[ pComponent ];

         return null;
      }

   ///<summary>
   /// Definition of the components that will be extended
   ///</summary>

      public bool CanExtend( object pComponent )
      {
         return( pComponent is MenuItem );
      }

      private StatusBarPanel m_StatusBar;

   ///<summary>
   /// Assign the StatusBarPanel that will display the menu's message
   ///</summary>

      public StatusBarPanel StatusBar
      {
         get{ return m_StatusBar;  }
         set{ m_StatusBar = value; }
      }

      private void Handle_MenuSelect( Object pControl, EventArgs e )
      {
         if( StatusBar == null )
            return;

         if( m_Dictionary.Contains( pControl ))
            StatusBar.Text = (string) m_Dictionary[ pControl ];
      }
   }
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Founder Zombies With Coffee, LLC
United States United States
Phillip has been a programmer long enough to remember cutting paper strip code out of Dr. Dobbs and running them thru a mechanical decoder to avoid typing in the samples.

Comments and Discussions