IHelpService 接口

定义

提供在设计时显示“帮助”主题和添加及移除“帮助”关键字的方法。Provides methods for showing Help topics and adding and removing Help keywords at design time.

public interface class IHelpService
public interface IHelpService
type IHelpService = interface
Public Interface IHelpService

示例

下面的示例演示一个设计器,该设计器使用 IHelpService 为包含的控件添加和移除帮助上下文特性。The following example demonstrates a designer that uses the IHelpService to add and remove Help context attributes for the included control. 若要使用此示例,请将其编译为类库并向添加控件的实例 FormTo use this sample, compile it to a class library and add an instance of the control to a Form. 在 "设计" 视图中,选择组件并按 F1 将尝试根据当前帮助上下文关键字或关键字查找相关帮助主题。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. 右键单击该组件,快捷菜单将显示命令,包括两个 DesignerVerb 名为和的自定义命令 Add IHelpService Help Keyword Remove IHelpService Help KeywordRight-click the component and the shortcut menu displays commands, including two custom DesignerVerb commands named Add IHelpService Help Keyword and Remove IHelpService Help Keyword. 这些命令可用于添加或删除值为 "IHelpService" 的帮助上下文关键字,该关键字会 IHelpService 在按 F1 时尝试引发主题。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 );
   }
};
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace IHelpServiceSample
{
    public class HelpDesigner : System.Windows.Forms.Design.ControlDesigner
    {
        public HelpDesigner()
        {			
        }

        public override System.ComponentModel.Design.DesignerVerbCollection Verbs
        {
            get
            {
                return new DesignerVerbCollection( new DesignerVerb[] { 
                        new DesignerVerb("Add IHelpService Help Keyword", new EventHandler(this.addKeyword)),
                        new DesignerVerb("Remove IHelpService Help Keyword", new EventHandler(this.removeKeyword))
                } );
            }
        }
        
        private void addKeyword(object sender, EventArgs e)
        {
            IHelpService hs = (IHelpService) this.Control.Site.GetService(typeof(IHelpService));			
            hs.AddContextAttribute("keyword", "IHelpService", HelpKeywordType.F1Keyword);	
        }
        
        private void removeKeyword(object sender, EventArgs e)
        {
            IHelpService hs = (IHelpService) this.Control.Site.GetService(typeof(IHelpService));			
            hs.RemoveContextAttribute("keyword", "IHelpService");
        }
    }

    [Designer(typeof(HelpDesigner))]
    public class HelpTestControl : System.Windows.Forms.UserControl
    {
        public HelpTestControl()
        {
            this.Size = new Size(320, 100);
            this.BackColor = Color.White;
        }

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

Namespace IHelpServiceSample

    Public Class HelpDesigner
        Inherits System.Windows.Forms.Design.ControlDesigner

        Public Sub New()
        End Sub

        Public Overrides ReadOnly Property Verbs() As System.ComponentModel.Design.DesignerVerbCollection
            Get
                Return New DesignerVerbCollection(New DesignerVerb() {New DesignerVerb("Add IHelpService Help Keyword", AddressOf Me.addKeyword), New DesignerVerb("Remove IHelpService Help Keyword", AddressOf Me.removeKeyword)})
            End Get
        End Property

        Private Sub addKeyword(ByVal sender As Object, ByVal e As EventArgs)
            Dim hs As IHelpService = CType(Me.Control.Site.GetService(GetType(IHelpService)), IHelpService)
            hs.AddContextAttribute("keyword", "IHelpService", HelpKeywordType.F1Keyword)
        End Sub

        Private Sub removeKeyword(ByVal sender As Object, ByVal e As EventArgs)
            Dim hs As IHelpService = CType(Me.Control.Site.GetService(GetType(IHelpService)), IHelpService)
            hs.RemoveContextAttribute("keyword", "IHelpService")
        End Sub
    End Class

    <Designer(GetType(HelpDesigner))> _
    Public Class HelpTestControl
        Inherits System.Windows.Forms.UserControl

        Public Sub New()
            Me.Size = New Size(320, 100)
            Me.BackColor = Color.White
        End Sub

        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            Dim brush As New SolidBrush(Color.Blue)
            e.Graphics.DrawString("IHelpService Example Designer Control", New Font(FontFamily.GenericMonospace, 10), brush, 5, 5)
            e.Graphics.DrawString("Right-click this component for", New Font(FontFamily.GenericMonospace, 8), brush, 5, 25)
            e.Graphics.DrawString("add/remove Help context keyword commands.", New Font(FontFamily.GenericMonospace, 8), brush, 5, 35)
            e.Graphics.DrawString("Press F1 while this component is", New Font(FontFamily.GenericMonospace, 8), brush, 5, 55)
            e.Graphics.DrawString("selected to raise Help topics for", New Font(FontFamily.GenericMonospace, 8), brush, 5, 65)
            e.Graphics.DrawString("the current keyword or keywords", New Font(FontFamily.GenericMonospace, 8), brush, 5, 75)
        End Sub
    End Class
End Namespace 'IHelpServiceSample

注解

设计时环境提供了一个帮助系统,该系统尝试查找在用户按 F1 时要显示的相关帮助主题。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.

IHelpService可用于通过使用方法调用具有指定关键字的帮助服务 ShowHelpFromKeyword ,或使用方法从指定的 URL 调用帮助主题 ShowHelpFromUrlThe 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.

IHelpService还可用于在设计时添加或删除帮助关键字。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. 你可以监视由接口定义的事件 ISelectionService ,以确定组件选择何时更改。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.

方法

AddContextAttribute(String, String, HelpKeywordType)

向该文档添加上下文特性。Adds a context attribute to the document.

ClearContextAttributes()

从文档中移除所有现有的上下文特性。Removes all existing context attributes from the document.

CreateLocalContext(HelpContextType)

创建用于管理子上下文的局部 IHelpServiceCreates a local IHelpService to manage subcontexts.

RemoveContextAttribute(String, String)

移除先前添加的上下文特性。Removes a previously added context attribute.

RemoveLocalContext(IHelpService)

移除用 CreateLocalContext(HelpContextType) 创建的上下文。Removes a context created with CreateLocalContext(HelpContextType).

ShowHelpFromKeyword(String)

显示对应于指定关键字的帮助主题。Shows the Help topic that corresponds to the specified keyword.

ShowHelpFromUrl(String)

显示对应于指定 URL 的帮助主题。Shows the Help topic that corresponds to the specified URL.

适用于

另请参阅