IHelpService Gränssnitt

Definition

Innehåller metoder för att visa hjälpavsnitt och lägga till och ta bort hjälpnyckelord vid designtillfället.

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

Exempel

I följande exempel visas en designer som använder IHelpService för att lägga till och ta bort hjälpkontextattribut för den inkluderade kontrollen. Om du vill använda det här exemplet kompilerar du det till ett klassbibliotek och lägger till en instans av kontrollen i en Form. I designvyn försöker du välja komponenten och trycka på F1 för att söka efter relevanta hjälpämnen baserat på det aktuella nyckelordet eller nyckelorden i hjälpkontexten. Högerklicka på komponenten och på snabbmenyn visas kommandon, inklusive två anpassade DesignerVerb kommandon med namnet Add IHelpService Help Keyword och Remove IHelpService Help Keyword. Dessa kommandon kan användas för att lägga till eller ta bort nyckelordet Hjälpkontext för värdet "IHelpService", som försöker höja IHelpService ämnet när F1 trycks på.

#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

Kommentarer

Design-time-miljön innehåller ett hjälpsystem som försöker hitta relevanta hjälpavsnitt som ska visas när en användare trycker på F1. Hjälpsystemet underhåller en uppsättning aktuella kontextnyckelord som används för att identifiera relevanta ämnen om hjälp begärs. Som standard associeras nyckelord med valda klassobjekt och egenskaper för objekt i designtidsmiljön. Standardnyckelordet för en komponent eller egenskap är dess fullständigt kvalificerade klass- eller egenskapsnamn. Specifika nyckelord är också associerade med vissa lägen, till exempel när flera objekt väljs. Om en anpassad hjälpsamling är integrerad med designtidsmiljön genom att konfigurera den för en extern hjälpleverantör, kan en dokumentationsprovider associera ett ämne för en specifik komponentklass eller egenskap med ett nyckelord som består av objektets fullständigt kvalificerade typ- eller medlemsnamn.

IHelpService Kan användas för att anropa hjälptjänsten med ett angivet nyckelord med hjälp av ShowHelpFromKeyword metoden eller för att anropa ett hjälpavsnitt från en angiven URL med hjälp av ShowHelpFromUrl metoden.

IHelpService Kan också användas för att lägga till eller ta bort hjälpnyckelord vid designtillfället. Om du väljer en komponent eller egenskap vid designtillfället anges ett standardkontextnyckelord som består av den fullständigt kvalificerade typen eller medlemsnamnet för markeringen och tar bort nyckelorden för tidigare valda och inte längre valda komponenter eller egenskaper.

Eftersom hjälpsystemet inte automatiskt tar bort anpassade hjälpnyckelord måste du uttryckligen ta bort ett anpassat nyckelord när det inte längre gäller. Du kan övervaka de händelser som definieras av ISelectionService gränssnittet för att avgöra när ett komponentval ändras. Baserat på dessa händelser kan du lägga till ett hjälpkontextattribut för en komponent när den väljs och sedan ta bort attributet Hjälpkontext när markeringen inte längre innehåller komponenten.

Metoder

Name Description
AddContextAttribute(String, String, HelpKeywordType)

Lägger till ett kontextattribut i dokumentet.

ClearContextAttributes()

Tar bort alla befintliga kontextattribut från dokumentet.

CreateLocalContext(HelpContextType)

Skapar en lokal IHelpService för att hantera underkontexter.

RemoveContextAttribute(String, String)

Tar bort ett tidigare tillagt kontextattribut.

RemoveLocalContext(IHelpService)

Tar bort en kontext som skapats med CreateLocalContext(HelpContextType).

ShowHelpFromKeyword(String)

Visar hjälpavsnittet som motsvarar det angivna nyckelordet.

ShowHelpFromUrl(String)

Visar hjälpavsnittet som motsvarar den angivna URL:en.

Gäller för

Se även