Factory.CreateSmartTag 方法

创建一个 SmartTag 对象,该对象表示文档中的一个智能标记。

命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word(在 Microsoft.Office.Tools.Word.dll 中)

语法

声明
Function CreateSmartTag ( _
    smartTagType As String, _
    caption As String, _
    extension As ISmartTagExtension _
) As SmartTag
SmartTag CreateSmartTag(
    string smartTagType,
    string caption,
    ISmartTagExtension extension
)

参数

  • smartTagType
    类型:System.String
    智能标记的唯一标识符,由命名空间 URI 和标记类型名组成,两部分之间用数字符号 (#) 分隔。
  • caption
    类型:System.String
    智能标记菜单上显示的智能标记的名称。

返回值

类型:Microsoft.Office.Tools.Word.SmartTag
新智能标记。

异常

异常 条件
ArgumentException

smartTagType 或 caption 为 nullnull 引用(在 Visual Basic 中为 Nothing) 或为空,或者 smartTagType 无效。

备注

smartTagType 参数的有效字符串的示例:http://smarttags.contoso.com#TagName。 格式良好的智能标记类型字符串不包含空白,它以字母(a-z、A-Z)、下划线 (_) 或冒号 (:) 开头。

有关智能标记的更多信息,请参见 智能标记概述智能标记的结构

示例

下面的代码示例演示如何在 Word 文档项目中创建智能标记和操作。 若要使用此示例,请在 ThisDocument 类中运行代码。

Dim simpleSmartTag As Microsoft.Office.Tools.Word.SmartTag =
    Globals.Factory.CreateSmartTag(
        "www.microsoft.com/Demo#DemoSmartTag",
        "Test Smart Tag")
Dim simpleAction As Microsoft.Office.Tools.Word.Action =
    Globals.Factory.CreateAction("Test Action")

simpleSmartTag.Terms.Add("blue")
simpleSmartTag.Actions = New Microsoft.Office.Tools.Word.Action() { _
    simpleAction}
Me.VstoSmartTags.Add(simpleSmartTag)
Microsoft.Office.Tools.Word.SmartTag simpleSmartTag =
    Globals.Factory.CreateSmartTag(
    "www.microsoft.com/Demo#DemoSmartTag",
    "Test Smart Tag");
Microsoft.Office.Tools.Word.Action simpleAction =
    Globals.Factory.CreateAction("Test Action");

simpleSmartTag.Terms.Add("blue");
simpleSmartTag.Actions = new Microsoft.Office.Tools.Word.Action[] { 
    simpleAction };
this.VstoSmartTags.Add(simpleSmartTag);

.NET Framework 安全性

请参见

参考

Factory 接口

Microsoft.Office.Tools.Word 命名空间