IHelpService Interfejs

Definicja

Udostępnia metody wyświetlania tematów Pomocy oraz dodawania i usuwania słów kluczowych Pomocy w czasie projektowania.

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

Przykłady

W poniższym przykładzie pokazano projektanta, który używa atrybutów IHelpService kontekstu do dodawania i usuwania pomocy dla dołączonej kontrolki. Aby użyć tego przykładu, skompiluj go do biblioteki klas i dodaj wystąpienie kontrolki do klasy Form. W widoku projektu wybranie składnika i naciśnięcie klawisza F1 próbuje wyszukać odpowiednie tematy Pomocy na podstawie bieżącego słowa kluczowego lub słów kluczowych kontekstu Pomocy. Kliknij prawym przyciskiem myszy składnik, a menu skrótów wyświetla polecenia, w tym dwa niestandardowe DesignerVerb polecenia o nazwie Add IHelpService Help Keyword i Remove IHelpService Help Keyword. Te polecenia mogą służyć do dodawania lub usuwania słowa kluczowego kontekstu Pomocy wartości "IHelpService", która próbuje zgłosić temat po naciśnięciu IHelpService klawisza F1.

#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

Uwagi

Środowisko czasu projektowania udostępnia system Pomocy, który próbuje zlokalizować odpowiednie tematy Pomocy do wyświetlenia, gdy użytkownik naciska klawisz F1. System Pomocy utrzymuje zestaw bieżących słów kluczowych kontekstu, które są używane do identyfikowania odpowiednich tematów, jeśli zostanie zażądana pomoc. Domyślnie słowa kluczowe są skojarzone z wybranymi obiektami klasy i właściwościami obiektów w środowisku czasu projektowania. Domyślnym słowem kluczowym składnika lub właściwości jest w pełni kwalifikowana nazwa klasy lub właściwości. Określone słowa kluczowe są również skojarzone z pewnymi trybami, takimi jak wybranie wielu obiektów. Jeśli niestandardowa kolekcja Pomocy jest zintegrowana ze środowiskiem czasu projektowania, konfigurując go dla zewnętrznego dostawcy pomocy, dostawca dokumentacji może skojarzyć temat dla określonej klasy składnika lub właściwości ze słowem kluczowym składającym się z w pełni kwalifikowanego typu lub nazwy elementu członkowskiego.

Można IHelpService go użyć do wywołania usługi pomocy z określonym słowem kluczowym przy użyciu ShowHelpFromKeyword metody lub wywołania tematu pomocy z określonego adresu URL przy użyciu ShowHelpFromUrl metody .

Można IHelpService go również użyć do dodawania lub usuwania słów kluczowych Pomocy w czasie projektowania. Wybranie składnika lub właściwości w czasie projektowania powoduje ustawienie domyślnego słowa kluczowego kontekstu składającego się z w pełni kwalifikowanego typu lub nazwy elementu członkowskiego zaznaczenia i usuwa słowa kluczowe dla wszystkich wcześniej wybranych składników lub właściwości.

Ponieważ system Pomocy nie usuwa automatycznie niestandardowych słów kluczowych Pomocy, należy jawnie usunąć niestandardowe słowo kluczowe, gdy już nie ma zastosowania. Zdarzenia zdefiniowane przez ISelectionService interfejs można monitorować, aby określić, kiedy wybór składnika ulegnie zmianie. Na podstawie tych zdarzeń można dodać atrybut kontekstu Pomocy dla składnika po jego wybraniu, a następnie usunąć atrybut kontekstu Pomocy, gdy zaznaczenie nie zawiera już składnika.

Metody

AddContextAttribute(String, String, HelpKeywordType)

Dodaje atrybut kontekstu do dokumentu.

ClearContextAttributes()

Usuwa wszystkie istniejące atrybuty kontekstu z dokumentu.

CreateLocalContext(HelpContextType)

Tworzy obiekt lokalny IHelpService do zarządzania podkontekstami.

RemoveContextAttribute(String, String)

Usuwa wcześniej dodany atrybut kontekstu.

RemoveLocalContext(IHelpService)

Usuwa kontekst utworzony za pomocą polecenia CreateLocalContext(HelpContextType).

ShowHelpFromKeyword(String)

Przedstawia temat Pomocy odpowiadający określonemu słowu kluczowemu.

ShowHelpFromUrl(String)

Przedstawia temat Pomocy odpowiadający określonemu adresowi URL.

Dotyczy

Zobacz też