IHelpService インターフェイス

定義

デザイン時に、ヘルプ トピックを表示し、ヘルプ キーワードの追加と削除を行うためのメソッドを提供します。

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

次の例では、 を使用 IHelpService して、含まれているコントロールのヘルプ コンテキスト属性を追加および削除するデザイナーを示します。 このサンプルを使用するには、クラス ライブラリにコンパイルし、 コントロールのインスタンスを に Form追加します。 デザイン ビューで、コンポーネントを選択し、F1 キーを押すと、現在のヘルプ コンテキスト のキーワードまたはキーワードに基づいて、関連するヘルプ トピックの検索が試みられます。 コンポーネントを右クリックすると、ショートカット メニューに と という名前Add IHelpService Help KeywordRemove IHelpService Help Keywordの 2 つのカスタム DesignerVerb コマンドを含むコマンドが表示されます。 これらのコマンドを使用すると、F1 キーを押したときにトピックの発生 IHelpService を試みる値 "IHelpService" のヘルプ コンテキスト キーワードを追加または削除できます。

#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 キーを押したときに表示する関連するヘルプ トピックの検索を試みるヘルプ システムが用意されています。 ヘルプ システムは、ヘルプが要求された場合に関連するトピックを識別するために使用される一連の現在のコンテキスト キーワードを保持します。 既定では、キーワードは選択したクラス オブジェクトとデザイン時環境のオブジェクトのプロパティに関連付けられます。 コンポーネントまたはプロパティの既定のキーワードは、その完全修飾クラスまたはプロパティ名です。 特定のキーワードは、複数のオブジェクトが選択されている場合など、特定のモードにも関連付けられます。 カスタム ヘルプ コレクションが外部ヘルプ プロバイダー用に構成することによってデザイン時環境と統合されている場合、ドキュメント プロバイダーは、特定のコンポーネント クラスまたはプロパティのトピックを、アイテムの完全修飾型またはメンバー名で構成されるキーワードに関連付けることができます。

IHelpService 使用すると、 メソッドを使用して指定したキーワードを使用してヘルプ サービスを呼び出したり、 メソッドを使用 ShowHelpFromKeyword して ShowHelpFromUrl 指定した URL からヘルプ トピックを呼び出したりできます。

IHelpServiceを使用して、デザイン時にヘルプ キーワードを追加または削除することもできます。 デザイン時にコンポーネントまたはプロパティを選択すると、選択範囲の完全修飾型またはメンバー名で構成される既定のコンテキスト キーワードが設定され、以前に選択され、選択されていないコンポーネントまたはプロパティのキーワードが削除されます。

ヘルプ システムはカスタム ヘルプ キーワードを自動的に削除しないため、カスタム キーワードが適用されなくなったときに明示的に削除する必要があります。 インターフェイスによって定義されたイベントを監視して、コンポーネントの ISelectionService 選択がいつ変わるかを判断できます。 これらのイベントに基づいて、コンポーネントが選択されたときにヘルプ コンテキスト属性を追加し、選択にコンポーネントが含まれない場合はヘルプ コンテキスト属性を削除できます。

メソッド

AddContextAttribute(String, String, HelpKeywordType)

コンテキスト属性をドキュメントに追加します。

ClearContextAttributes()

ドキュメントから既存のコンテキスト属性をすべて削除します。

CreateLocalContext(HelpContextType)

ローカル IHelpService を作成し、サブコンテキストを管理します。

RemoveContextAttribute(String, String)

以前に追加したコンテキスト属性を削除します。

RemoveLocalContext(IHelpService)

CreateLocalContext(HelpContextType) を使用して作成したコンテキストを削除します。

ShowHelpFromKeyword(String)

指定したキーワードに対応するヘルプ トピックを表示します。

ShowHelpFromUrl(String)

指定した URL に対応するヘルプ トピックを表示します。

適用対象

こちらもご覧ください