IHelpService Interfaccia

Definizione

Fornisce metodi per visualizzare la Guida e aggiungere e rimuovere parole chiave della Guida in fase di progettazione.

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

Esempio

Nell'esempio seguente viene illustrata una finestra di progettazione che usa per IHelpService aggiungere e rimuovere gli attributi di contesto della Guida per il controllo incluso. Per usare questo esempio, compilarlo in una libreria di classi e aggiungere un'istanza del controllo a un oggetto Form. Nella visualizzazione progettazione selezionare il componente e premere F1 per cercare gli argomenti della Guida pertinenti in base alla parola chiave o alle parole chiave correnti del contesto della Guida. Fare clic con il pulsante destro del mouse sul componente e il menu di scelta rapida visualizza i comandi, inclusi due comandi personalizzati DesignerVerb denominati Add IHelpService Help Keyword e Remove IHelpService Help Keyword. Questi comandi possono essere usati per aggiungere o rimuovere una parola chiave del contesto della Guida del valore "IHelpService", che tenta di generare l'argomento IHelpService quando viene premuto 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

Commenti

L'ambiente in fase di progettazione fornisce un sistema della Guida che tenta di individuare gli argomenti della Guida pertinenti da visualizzare quando un utente preme F1. Il sistema della Guida gestisce un set di parole chiave di contesto correnti usate per identificare gli argomenti pertinenti se viene richiesta la Guida. Per impostazione predefinita, le parole chiave sono associate a oggetti classe selezionati e proprietà di oggetti nell'ambiente della fase di progettazione. La parola chiave predefinita per un componente o una proprietà è il nome completo della classe o della proprietà. Le parole chiave specifiche sono associate anche a determinate modalità, ad esempio quando vengono selezionati più oggetti. Se una raccolta guida personalizzata è integrata con l'ambiente in fase di progettazione configurandola per un provider della Guida esterna, un provider di documentazione può associare un argomento per una classe o una proprietà del componente specifica a una parola chiave costituita dal tipo o dal nome del membro completo dell'elemento.

Può IHelpService essere utilizzato per richiamare il servizio Guida con una parola chiave specificata usando il ShowHelpFromKeyword metodo oppure per richiamare un argomento della Guida da un URL specificato usando il ShowHelpFromUrl metodo .

Può IHelpService anche essere usato per aggiungere o rimuovere parole chiave della Guida in fase di progettazione. Se si seleziona un componente o una proprietà in fase di progettazione, viene impostata una parola chiave di contesto predefinita costituita dal tipo completo o dal nome del membro della selezione e vengono rimosse le parole chiave per qualsiasi componente o proprietà selezionata in precedenza e non più selezionata.

Poiché il sistema della Guida non rimuove automaticamente le parole chiave personalizzate della Guida, è necessario rimuovere in modo esplicito una parola chiave personalizzata quando non viene più applicata. È possibile monitorare gli eventi definiti dall'interfaccia ISelectionService per determinare quando cambia la selezione di un componente. In base a questi eventi, è possibile aggiungere un attributo di contesto della Guida per un componente quando è selezionato e quindi rimuovere l'attributo di contesto della Guida quando la selezione non include più il componente.

Metodi

AddContextAttribute(String, String, HelpKeywordType)

Aggiunge un attributo di contesto al documento.

ClearContextAttributes()

Rimuove dal documento tutti gli attributi di contesto esistenti.

CreateLocalContext(HelpContextType)

Crea un oggetto IHelpService locale per gestire i sottocontesti.

RemoveContextAttribute(String, String)

Rimuove un attributo di contesto aggiunto precedentemente.

RemoveLocalContext(IHelpService)

Rimuove un contesto creato con CreateLocalContext(HelpContextType).

ShowHelpFromKeyword(String)

Mostra l'argomento della Guida corrispondente alla parola chiave specificata.

ShowHelpFromUrl(String)

Mostra l'argomento della Guida corrispondente all'URL specificato.

Si applica a

Vedi anche