Aracılığıyla paylaş


ISmartTagExtension Arabirim

Akıllı etiket Visual Studio'da Office geliştirme araçlarını kullanarak özelleştirilmiş bir Word belgesindeki bir uzantısı temsil eder. Akıllı etiket için özel bir tanıyıcı uzantısını tanımlar.

Ad alanı:  Microsoft.Office.Tools.Word
Derleme:  Microsoft.Office.Tools.Word (Microsoft.Office.Tools.Word.dll içinde)

Sözdizimi

'Bildirim
<GuidAttribute("B4244E14-AB13-432F-8D7B-70BBA2A3EA67")> _
Public Interface ISmartTagExtension _
    Inherits IExtension
[GuidAttribute("B4244E14-AB13-432F-8D7B-70BBA2A3EA67")]
public interface ISmartTagExtension : IExtension

ISmartTagExtension türü aşağıdaki üyeleri ortaya koyar.

Özellikler

  Ad Açıklama
Genel özellik ExtensionBase Bu uzatılmış nesne alır IExtension. (IExtension kaynağından devralındı.)

Üst

Yöntemler

  Ad Açıklama
Genel yöntem Recognize Metin belgede tanınan koşulları arar.

Üst

Açıklamalar

Implement ISmartTagExtension arabirimi Word akıllı etiketleri nasıl tanır denetlemek istiyorsanızbelgeleri. Daha fazla bilgi için bkz:Akıllı Etiketler Mimarisi ve Nasıl Yapılır: Word and .NET Framework 4'te Özel Tanıyıcılarla Akıllı Etiketler Oluşturma.

Kullanım

Bu tür projelerde yalnızca Word 2007 için kullanılmak üzere hazırlanmıştır. Akıllı etiketler Word 2010 kaldırılmıştır. Daha fazla bilgi için bkz. Akıllı Etiketlere Genel Bakış.

Örnekler

Aşağıdaki kod örneği nasıl uygulanacağını gösteren ISmartTagExtension oluşturmak kendi akıllı etiket tanıyıcı. Örnek uygulayan Recognize yöntemi her akıllı etiket terim tanımak için bulunan bir paragraf. Bu örnek, bir başvuru eklediğinizi varsayar Microsoft.Office.Interop.SmartTag dan .net sekmesinde Add Reference iletişim kutusu.

Imports System
Imports System.Windows.Forms
Imports Microsoft.Office.Interop.SmartTag
Imports Microsoft.Office.Tools.Word

Public Class CustomSmartTag
    Implements ISmartTagExtension
    ' Declare the smart tag.
    Private smartTagDemo As Microsoft.Office.Tools.Word.SmartTag

    ' Declare actions for this smart tag.
    WithEvents Action1 As Microsoft.Office.Tools.Word.Action
    WithEvents Action2 As Microsoft.Office.Tools.Word.Action

    Public Sub New()
        Me.smartTagDemo = Globals.Factory.CreateSmartTag(
            "https://www.contoso.com/Demo#DemoSmartTag", "Custom Smart Tag", Me)

        Action1 = Globals.Factory.CreateAction("Display property value")
        Action2 = Globals.Factory.CreateAction("Display smart tag details")

        smartTagDemo.Terms.AddRange(New String() {"sales", "organization"})
        smartTagDemo.Actions = New Microsoft.Office.Tools.Word.Action() {Action1, Action2}

    End Sub

    Private Sub Recognize(ByVal text As String,
        ByVal site As ISmartTagRecognizerSite,
        ByVal tokenList As ISmartTagTokenList,
        ByVal context As SmartTagRecognizeContext) Implements ISmartTagExtension.Recognize

        For Each term As String In smartTagDemo.Terms
            ' Search the text for the current smart tag term.
            Dim index As Integer = text.IndexOf(term, 0)

            While (index >= 0)
                ' Create a smart tag token and a property bag for the recognized term.
                Dim propertyBag As ISmartTagProperties = site.GetNewPropertyBag()

                ' Write a new property value.
                Dim key As String = "Key1"
                propertyBag.Write(key, DateTime.Now.ToString())

                ' Attach the smart tag to the term in the document
                context.PersistTag(index, term.Length, propertyBag)

                ' Increment the index and then find the next instance of the smart tag term.
                index += term.Length
                index = text.IndexOf(term, index)
            End While
        Next
    End Sub

    ' This action displays the property value for the term.
    Private Sub Action1_Click(ByVal sender As Object,
        ByVal e As Microsoft.Office.Tools.Word.ActionEventArgs) Handles Action1.Click
        Dim propertyBag As ISmartTagProperties = e.Properties
        Dim key As String = "Key1"
        MessageBox.Show(("The corresponding value of " & key & " is: ") + propertyBag.Read(key))
    End Sub

    ' This action displays smart tag details.
    Private Sub Action2_Click(ByVal sender As Object,
        ByVal e As Microsoft.Office.Tools.Word.ActionEventArgs) Handles Action2.Click
        MessageBox.Show(("The current smart tag caption is '" &
            smartTagDemo.Caption & "'. The current smart tag type is '") &
            smartTagDemo.SmartTagType & "'.")
    End Sub

    Public ReadOnly Property Base() As Microsoft.Office.Tools.Word.SmartTag
        Get
            Return (smartTagDemo)
        End Get
    End Property

    Public ReadOnly Property ExtensionBase() As Object Implements ISmartTagExtension.ExtensionBase
        Get
            Return (smartTagDemo)
        End Get
    End Property
End Class
using System;
using System.Windows.Forms;
using Microsoft.Office.Interop.SmartTag;
using Microsoft.Office.Tools.Word;

namespace CustomSmartTagExample
{
    public class CustomSmartTag : ISmartTagExtension
    {
        // Declare the smart tag.
        Microsoft.Office.Tools.Word.SmartTag smartTagDemo;

        // Declare actions for this smart tag.
        private Microsoft.Office.Tools.Word.Action Action1;
        private Microsoft.Office.Tools.Word.Action Action2;

        public CustomSmartTag()
        {
            this.smartTagDemo = Globals.Factory.CreateSmartTag(
                "https://www.contoso.com/Demo#DemoSmartTag", "Custom Smart Tag", this);

            Action1 = Globals.Factory.CreateAction("Display property value");
            Action2 = Globals.Factory.CreateAction("Display smart tag details");

            smartTagDemo.Terms.AddRange(new string[] { "sales", "organization" });
            smartTagDemo.Actions = new Microsoft.Office.Tools.Word.Action[] { Action1, Action2 };

            Action1.Click += new ActionClickEventHandler(Action1_Click);
            Action2.Click += new ActionClickEventHandler(Action2_Click);
        }

        void ISmartTagExtension.Recognize(string text, ISmartTagRecognizerSite site, ISmartTagTokenList tokenList, 
            SmartTagRecognizeContext context)
        {

            foreach (string term in smartTagDemo.Terms)
            {
                // Search the text for the current smart tag term.
                int index = text.IndexOf(term, 0);

                while (index >= 0)
                {
                    // Create a smart tag token and a property bag for the recognized term.
                    ISmartTagProperties propertyBag = site.GetNewPropertyBag();

                    // Write a new property value.
                    string key = "Key1";
                    propertyBag.Write(key, DateTime.Now.ToString());

                    // Attach the smart tag to the term in the document
                    context.PersistTag(index, term.Length, propertyBag);

                    // Increment the index and then find the next instance of the smart tag term.
                    index += term.Length;
                    index = text.IndexOf(term, index);
                }
            }
        }

        // This action displays the property value for the term.
        private void Action1_Click(object sender,
            Microsoft.Office.Tools.Word.ActionEventArgs e)
        {
            ISmartTagProperties propertyBag = e.Properties;
            string key = "Key1";
            MessageBox.Show("The corresponding value of " + key + " is: " + propertyBag.get_Read(key));
        }

        // This action displays smart tag details.
        private void Action2_Click(object sender,
            Microsoft.Office.Tools.Word.ActionEventArgs e)
        {
            MessageBox.Show("The current smart tag caption is '" +
                smartTagDemo.Caption + "'. The current smart tag type is '" + smartTagDemo.SmartTagType + "'.");
        }


        public Microsoft.Office.Tools.Word.SmartTag Base
        {
            get { return smartTagDemo; }
        }

        public object ExtensionBase
        {
            get { return smartTagDemo; }
        }

    }
}

Ayrıca bkz.

Başvuru

Microsoft.Office.Tools.Word Ad Alanı

Diğer Kaynaklar

Akıllı Etiketler Mimarisi

Nasıl Yapılır: Word and .NET Framework 4'te Özel Tanıyıcılarla Akıllı Etiketler Oluşturma