語言

IHelpService 介面

定義

提供在設計時顯示說明主題及新增與移除幫助關鍵字的方法。

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

範例

以下範例示範一個設計器,該設計器使用 來 IHelpService 新增與移除 Help 上下文屬性,來處理包含控制項。 使用此範例時,編譯為類別庫,並將控制項實例加入 Form。 在設計檢視中,選擇元件並按下 F1 鍵,嘗試根據當前的 Help 上下文關鍵字查詢相關的說明主題。 右鍵點擊元件,捷徑選單會顯示指令,包括兩個名為 DesignerVerb 和 Add IHelpService Help Keyword的自訂Remove IHelpService Help Keyword指令。 這些指令可用來新增或移除「IHelpService」的幫助上下文關鍵字,當按下 F1 時嘗試喚起該 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指定網址呼叫說明主題。

它們 IHelpService 也可以在設計時新增或移除幫助關鍵字。 在設計時選擇元件或屬性時,會設定一個預設的上下文關鍵字,包含該選擇的完全限定型別或成員名稱,並移除先前已選取或不再選取的元件或屬性的關鍵字。

由於說明系統不會自動移除自訂的幫助關鍵字,當自訂關鍵字不再適用時,你必須明確移除它。 你可以監控介面定義的 ISelectionService 事件,判斷元件選擇何時改變。 根據這些事件,你可以在選擇元件時新增一個幫助上下文屬性,當選擇中不再包含該元件時,再移除該幫助上下文屬性。

方法

名稱 Description
AddContextAttribute(String, String, HelpKeywordType)

為文件新增一個上下文屬性。

ClearContextAttributes()

移除文件中所有現有的上下文屬性。

CreateLocalContext(HelpContextType)

建立一個 IHelpService 本地節點來管理子上下文。

RemoveContextAttribute(String, String)

移除先前新增的上下文屬性。

RemoveLocalContext(IHelpService)

移除由 所 CreateLocalContext(HelpContextType)建立的上下文。

ShowHelpFromKeyword(String)

顯示對應指定關鍵字的說明主題。

ShowHelpFromUrl(String)

顯示對應指定網址的說明主題。

適用於

另請參閱