IHelpService 接口

提供在设计时显示“帮助”主题和添加及移除“帮助”关键字的方法。

**命名空间:**System.ComponentModel.Design
**程序集:**System(在 system.dll 中)

语法

声明
Public Interface IHelpService
用法
Dim instance As IHelpService
public interface IHelpService
public interface class IHelpService
public interface IHelpService
public interface IHelpService

备注

设计时环境提供的“帮助”系统在用户按 F1 键时尝试定位要显示的相关“帮助”主题。该“帮助”系统维护一组当前的上下文关键字,这些关键字在请求“帮助”时用于标识相关主题。默认情况下,关键字与设计时环境中的选定类对象及对象属性关联。组件或属性的默认关键字是它的完全限定类名或属性名。特定关键字也与特定模式(例如,选定多个对象时)关联。如果通过为外部帮助提供程序配置自定义的“帮助”集合而使该集合与设计时环境集成在一起,那么文档提供程序可以使特定组件类或属性的主题与关键字关联,该关键字由项的完全限定类型或成员名组成。

IHelpService 可用于:利用 ShowHelpFromKeyword 方法通过指定的关键字调用帮助服务,或者利用 ShowHelpFromUrl 方法从指定的 URL 调用帮助主题。

IHelpService 还可用于在设计时添加或移除“帮助”关键字。在设计时选择组件或属性,会设置由所选内容的完全限定类型或成员名组成的默认上下文关键字,并且移除任何以前选定但现已不再选定的组件或属性的关键字。

由于“帮助”系统不会自动移除自定义的“帮助”关键字,因此必须显式移除不再应用的自定义关键字。您可以通过监视 ISelectionService 接口定义的事件来确定组件所选内容的更改时间。根据这些事件,您可以在组件被选定时为它添加“帮助”上下文属性,然后在所选内容中不再包括该组件时移除“帮助”上下文属性。

示例

下面的示例演示一个设计器,该设计器使用 IHelpService 来添加或移除所包含控件的帮助上下文属性。若要使用此示例,请将其编译为一个类库,并将该控件的一个实例添加到 Form。在“设计”视图中,选择组件并按 F1 以尝试基于当前帮助上下文关键字查找相关帮助主题。右击组件,快捷菜单即显示命令,其中包括两个名为 Add IHelpService Help KeywordRemove IHelpService Help Keyword 的自定义 DesignerVerb 命令。这些命令可用于添加或移除值为“IHelpService”的帮助上下文关键字,该关键字在按下 F1 时会尝试引发 IHelpService 主题。

Imports System
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 'New

        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 'addKeyword

        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 'removeKeyword
    End Class 'HelpDesigner

    <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 'New

        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 'OnPaint
    End Class 'HelpTestControl
End Namespace 'IHelpServiceSample
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);         
        }       
    }
}
#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 );
   }
};
package IHelpServiceSample; 
import System.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.Drawing.*;
import System.IO.*;
import System.Windows.Forms.*;
import System.Windows.Forms.Design.*;

public class HelpDesigner extends System.Windows.Forms.Design.ControlDesigner
{
    public HelpDesigner()
    {
    } //HelpDesigner

    /** @property 
     */
    public System.ComponentModel.Design.DesignerVerbCollection get_Verbs()
    {
        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)) });
    } //get_Verbs

    private void AddKeyword(Object sender, EventArgs e)
    {
        IHelpService hs = (IHelpService)(this.get_Control().get_Site().
            GetService(IHelpService.class.ToType()));
        hs.AddContextAttribute("keyword", "IHelpService", 
            HelpKeywordType.F1Keyword);
    } //AddKeyword

    private void RemoveKeyword(Object sender, EventArgs e)
    {
        IHelpService hs = (IHelpService)(this.get_Control().get_Site().
            GetService(IHelpService.class.ToType()));
        hs.RemoveContextAttribute("keyword", "IHelpService");
    } //RemoveKeyword
} //HelpDesigner

/** @attribute Designer(HelpDesigner.class)
 */
public class HelpTestControl extends System.Windows.Forms.UserControl
{
    public HelpTestControl()
    {
        this.set_Size(new Size(320, 100));
        this.set_BackColor(Color.get_White());
    } //HelpTestControl

    protected void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        Brush brush = new SolidBrush(Color.get_Blue());

        e.get_Graphics().DrawString("IHelpService Example Designer Control",
            new Font(FontFamily.get_GenericMonospace(), 10), brush, 5, 5);
        e.get_Graphics().DrawString("Right-click this component for", 
            new Font(FontFamily.get_GenericMonospace(), 8), brush, 5, 25);
        e.get_Graphics().DrawString("add/remove Help context keyword commands.",
            new Font(FontFamily.get_GenericMonospace(), 8), brush, 5, 35);
        e.get_Graphics().DrawString("Press F1 while this component is", 
            new Font(FontFamily.get_GenericMonospace(), 8), brush, 5, 55);
        e.get_Graphics().DrawString("selected to raise Help topics for", 
            new Font(FontFamily.get_GenericMonospace(), 8), brush, 5, 65);
        e.get_Graphics().DrawString("the current keyword or keywords", 
            new Font(FontFamily.get_GenericMonospace(), 8), brush, 5, 75);
    } //OnPaint
} //HelpTestControl

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

IHelpService 成员
System.ComponentModel.Design 命名空间
HelpKeywordType 枚举
HelpContextType 枚举