This documentation is archived and is not being maintained.

IHelpService Interface

Provides methods for showing Help topics and adding and removing Help keywords at design time.

Namespace:  System.ComponentModel.Design
Assembly:  System (in System.dll)

public interface class IHelpService

The IHelpService type exposes the following members.

  NameDescription
Public methodAddContextAttributeAdds a context attribute to the document.
Public methodClearContextAttributesRemoves all existing context attributes from the document.
Public methodCreateLocalContextCreates a local IHelpService to manage subcontexts.
Public methodRemoveContextAttributeRemoves a previously added context attribute.
Public methodRemoveLocalContextRemoves a context created with CreateLocalContext.
Public methodShowHelpFromKeywordShows the Help topic that corresponds to the specified keyword.
Public methodShowHelpFromUrlShows the Help topic that corresponds to the specified URL.
Top

The design-time environment provides a Help system that attempts to locate relevant Help topics to display when a user presses F1. The Help system maintains a set of current context keywords that are used to identify relevant topics if Help is requested. By default, keywords are associated with selected class objects and properties of objects in the design time environment. The default keyword for a component or property is its fully qualified class or property name. Specific keywords are also associated with certain modes, such as when multiple objects are selected. If a custom Help collection is integrated with the design-time environment by configuring it for an external help provider, a documentation provider can associate a topic for a specific component class or property with a keyword consisting of the item's fully qualified type or member name.

The IHelpService can be used to invoke the help service with a specified keyword using the ShowHelpFromKeyword method, or to invoke a help topic from a specified URL using the ShowHelpFromUrl method.

The IHelpService can also be used to add or remove Help keywords at design time. Selecting a component or property at design time sets a default context keyword consisting of the fully qualified type or member name of the selection, and removes the keywords for any previously selected and no longer selected components or properties.

Because the Help system does not automatically remove custom Help keywords, you must explicitly remove a custom keyword when it no longer applies. You can monitor the events defined by the ISelectionService interface to determine when a component selection changes. Based on those events, you can add a Help context attribute for a component when it is selected and then remove the Help context attribute when the selection no longer includes the component.

The following example demonstrates a designer that uses the IHelpService to add and remove Help context attributes for the included control. To use this sample, compile it to a class library and add an instance of the control to a Form. In design view, selecting the component and pressing F1 attempts to look up relevant Help topics based on the current Help context keyword or keywords. Right-click the component and the shortcut menu displays commands, including two custom DesignerVerb commands named Add IHelpService Help Keyword and Remove IHelpService Help Keyword. These commands can be used to add or remove a Help context keyword of the value "IHelpService", which attempts to raise the IHelpService topic when F1 is pressed.


#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#using <System.Design.dll>
#using <System.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::Design;

public ref class HelpDesigner: public System::Windows::Forms::Design::ControlDesigner
{
public:
   HelpDesigner(){}

   property System::ComponentModel::Design::DesignerVerbCollection^ Verbs 
   {
      virtual System::ComponentModel::Design::DesignerVerbCollection^ get() override
      {
         array<DesignerVerb^>^temp0 = {gcnew DesignerVerb( "Add IHelpService Help Keyword",gcnew EventHandler( this, &HelpDesigner::addKeyword ) ),gcnew DesignerVerb( "Remove IHelpService Help Keyword",gcnew EventHandler( this, &HelpDesigner::removeKeyword ) )};
         return gcnew DesignerVerbCollection( temp0 );
      }
   }

private:
   void addKeyword( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      IHelpService^ hs = dynamic_cast<IHelpService^>(this->Control->Site->GetService( IHelpService::typeid ));
      hs->AddContextAttribute( "keyword", "IHelpService", HelpKeywordType::F1Keyword );
   }

   void removeKeyword( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      IHelpService^ hs = dynamic_cast<IHelpService^>(this->Control->Site->GetService( IHelpService::typeid ));
      hs->RemoveContextAttribute( "keyword", "IHelpService" );
   }
};


[Designer(HelpDesigner::typeid)]
public ref class HelpTestControl: public System::Windows::Forms::UserControl
{
public:
   HelpTestControl()
   {
      this->Size = System::Drawing::Size( 320, 100 );
      this->BackColor = Color::White;
   }

protected:
   virtual void OnPaint( System::Windows::Forms::PaintEventArgs^ e ) override
   {
      Brush^ brush = gcnew SolidBrush( Color::Blue );
      e->Graphics->DrawString( "IHelpService Example Designer Control", gcnew System::Drawing::Font( FontFamily::GenericMonospace,10 ), brush, 5, 5 );
      e->Graphics->DrawString( "Right-click this component for", gcnew System::Drawing::Font( FontFamily::GenericMonospace,8 ), brush, 5, 25 );
      e->Graphics->DrawString( "add/remove Help context keyword commands.", gcnew System::Drawing::Font( FontFamily::GenericMonospace,8 ), brush, 5, 35 );
      e->Graphics->DrawString( "Press F1 while this component is", gcnew System::Drawing::Font( FontFamily::GenericMonospace,8 ), brush, 5, 55 );
      e->Graphics->DrawString( "selected to raise Help topics for", gcnew System::Drawing::Font( FontFamily::GenericMonospace,8 ), brush, 5, 65 );
      e->Graphics->DrawString( "the current keyword or keywords", gcnew System::Drawing::Font( FontFamily::GenericMonospace,8 ), brush, 5, 75 );
   }
};


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: