#眉標=Office、VSTO、WordML #副標=Office 2007開發系列(12) #大標=整合智慧標籤與VSTO #作者=文/圖 沈炳宏 ============= 程式1 Imports Microsoft.Office.Tools.Word Public Class ThisDocument Private Sub ThisDocument_Startup( ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Startup Dim mySmartTag As New SmartTag( _ "http://runpc.com.tw#demoSmartTag", "智慧標籤demo") mySmartTag.Terms.Add("demo") mySmartTag.Terms.Add("test") Dim myAction As New Action("執行動作1") Dim myAction2 As New Action("執行動作2") mySmartTag.Actions = New Action() {myAction, myAction2} AddHandler myAction.Click, AddressOf myAction_Click AddHandler myAction2.Click, AddressOf myAction2_Click Me.VstoSmartTags.Add(mySmartTag) End Sub Private Sub myAction_Click( ByVal sender As Object, _ ByVal e As ActionEventArgs) MsgBox(“動作1”) End Sub Private Sub myAction2_Click( ByVal sender As Object, _ ByVal e As ActionEventArgs) MsgBox(“動作2”) End Sub End Class ================ ============= 程式2 Class CustomSmartTag Inherits Microsoft.Office.Tools.Word.SmartTag Private WithEvents customAction As Action Friend Sub New() … End Sub Private Sub customAction_Click( ByVal sender As Object, _ ByVal e As ActionEventArgs) Handles customAction.Click Dim props As SmartTag. … End Sub Protected Overrides Sub Recognize( … textToFind, startIndex) >= 0 … If IsValidEmployee( employeeNumber, price) Then … End While End Sub Private Function IsValidEmployee( ByVal Employee As String, _ ByRef price As String) As Boolean Dim numericEmployee As Int32 = 0 Try numericEmployee = Convert.ToInt32( _ EmployeeSubstring(2, 4)) Dim rnd As New Random() price = rnd.Next(50000).ToString() … End Function End Class ================ ===<反灰>============= caspol -user -addgroup "All_Code" url c:\ EmployeeNumberSmartTag\ EmployeeNumberSmartTag.dll FullTrust -name "EmployeeNumberSmartTag" ================