IHelpService 接口
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供用于在设计时显示帮助主题和添加和删除帮助关键字的方法。
public interface class IHelpService
public interface IHelpService
type IHelpService = interface
Public Interface IHelpService
示例
以下示例演示了一个设计器,该设计器使用 IHelpService 添加和删除包含控件的帮助上下文属性。 若要使用此示例,请将其编译为类库,并将控件的实例添加到类 Form库。 在设计视图中,选择组件并按 F1 会尝试基于当前帮助上下文关键字或关键字查找相关的帮助主题。 右键单击组件,快捷菜单显示命令,包括两个命名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指定的关键字调用帮助服务,或使用该方法从指定的 URL ShowHelpFromUrl 调用帮助主题。
IHelpService还可以用于在设计时添加或删除帮助关键字。 在设计时选择组件或属性将设置一个默认上下文关键字,该关键字由所选内容的完全限定类型或成员名称组成,并删除以前选择的任何组件或属性的关键字,并且不再选择组件或属性。
由于帮助系统不会自动删除自定义帮助关键字,因此在不再应用自定义关键字时,必须显式删除该关键字。 可以监视接口定义的 ISelectionService 事件,以确定组件选择何时发生更改。 根据这些事件,可以在选择组件时为组件添加帮助上下文属性,然后在选择不再包含该组件时删除帮助上下文属性。
方法
| 名称 | 说明 |
|---|---|
| AddContextAttribute(String, String, HelpKeywordType) |
向文档添加上下文属性。 |
| ClearContextAttributes() |
从文档中删除所有现有上下文属性。 |
| CreateLocalContext(HelpContextType) |
创建用于管理子文本的本地 IHelpService 。 |
| RemoveContextAttribute(String, String) |
删除以前添加的上下文属性。 |
| RemoveLocalContext(IHelpService) |
删除使用 CreateLocalContext(HelpContextType). 创建的上下文。 |
| ShowHelpFromKeyword(String) |
显示与指定关键字对应的帮助主题。 |
| ShowHelpFromUrl(String) |
显示与指定 URL 对应的帮助主题。 |