|
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.
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.