Inserimento della classe Action:
La classe Action permette di eseguire la varie azioni dello
smart tag. Quindi dobbiamo inserire una nuova classe, facciamo click con il pulsante
destro del mouse, sul nome del progetto, dal menu che viene visualizzato selezioniamo
la voce nuova classe. Come nome gli assegniamo il valore Action.Anche in questa
classe bisogna importare il namespace smart tag e interoperabilità.
Quindi in alto sopra ad ogni scritta scriviamo il seguente codice:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop.SmartTag
Anche per questa classe dobbiamo assegnare una guid, come visto
in precedenza per la classe recognizer, quindi la procedura sarà la medisima
Il codice dev'essere simile come qui di seguito illustrato.
<ProgId("SmartTagE
manuele.Action"), _
GuidAttribute("0C832FB2-717D-443f-AD90-DBFE42072FFE"),
_
ComVisible(True)> _
Public Class Action
La classe Action, deve implementare l'interfaccia ISmartTagAction
quindi scriveremo sotto a class Action il seguente codice:
Public Class Action
Implements ISmartTagAction
Anche qui dopo la scritta ismarttagaction digitando il pulsante
della tastiera invio in questo modo verranno automaticamente riportale le varie
prorpietà e
metodi di tale interfaccia.
Proprietà Desc:
Questa proprietà ha il compito di impostare la descrizione
della classe action.
Public ReadOnly Property Desc(ByVal LocaleID As
Integer) As String Implements Microsoft.Office.Interop.SmartTag.ISmartTagAction.Desc
Get
'descrizione
della classe action
Return "Descrizione
della classe action"
End
Get
End Property
Metodo invokeverb
TAle metodo ha il compito di eseguire l'azione sulle varie
voci che vengono visualizzati durante l'apertura dello smart tag (figura 6),
per esempio se noi abbiamo due voci una con la scritta email e l'altra con la
scritta sito, a seconda della voce che verrà selezionata eseguirà una
determinata azione.

Figura 6
Public Sub InvokeVerb(ByVal VerbID As Integer,
ByVal ApplicationName As String, ByVal Target As Object, ByVal Properties As
Microsoft.Office.Interop.SmartTag.ISmartTagProperties, ByVal Text As String,
ByVal Xml As String) Implements Microsoft.Office.Interop.SmartTag.ISmartTagAction.InvokeVerb
'verifico
che voce è stata selezionata
Select
Case VerbID
Case
1 'e
mail
System.Diagnostics.Process.Start("mailto:
e
manuelemattei@email.it
")
Case
2 'sito
System.Diagnostics.Process.Start("http://www.shareoffice.it")
End
Select
End Sub
La proprietà name
imposta il nome per la classe action.
Public ReadOnly Property Name(ByVal LocaleID As
Integer) As String Implements Microsoft.Office.Interop.SmartTag.ISmartTagAction.Name
Get
'imposto
il nome per la classe action
Return "
Nome
Action"
End
Get
End Property
Proprietà ProgId
Questa proprietà imposta l'id della classe action da notare che tale
id è il nome della classe preceduto dal nome del progetto.
Public ReadOnly Property ProgId() As String Implements
Microsoft.Office.Interop.SmartTag.ISmartTagAction.ProgId
Get
'ritorna
l'id della classe action
Return "SmartTagE
manuele.Action"
End
Get
End Property
La proprietà SmartTagCaption:
Questa proprietà ha il compito di visualizzare una descrizione nella
finestra dei smart tag (figura 5), questo testo precede il nome di tale
smart tag.
Public ReadOnly Property SmartTagCaption(ByVal
SmartTagID As Integer, ByVal LocaleID As Integer) As String Implements Microsoft.Office.Interop.SmartTag.ISmartTagAction.SmartTagCaption
Get
'il
valore che verrà visualizzato nella finestra smart tag
Return "Esempio
di smartTag"
End
Get
End Property
La proprietà smarttagcount
Questa proprietà ha il compito di indicare il numero
dei smart tag. Nel nostro caso uno
Public ReadOnly Property SmartTagCount() As Integer
Implements Microsoft.Office.Interop.SmartTag.ISmartTagAction.SmartTagCount
Get
'
il numero dei smart tag
Return
1
End
Get
End Property
La proprietà SmartTagName
Questa proprietà ha il compito di visualizzare il nome
dello smart tag.
Public ReadOnly Property SmartTagName(ByVal SmartTagID
As Integer) As String Implements Microsoft.Office.Interop.SmartTag.ISmartTagAction.SmartTagName
Get
'il
nome dello smart tag che si vuole eseguire.
Return "urn:esempio-smarttag#SmartTagE
manuele"
End
Get
End Property
La proprietà VerbCaptionFromId
Questa proprietà ha il compito di visualizzare le varie
voci dello smart tag.
Tramite l'argomento VerbId indica il numero di indice di tali voci.
Public ReadOnly Property VerbCaptionFromID(ByVal
VerbID As Integer, ByVal ApplicationName As String, ByVal LocaleID As Integer)
As String Implements Microsoft.Office.Interop.SmartTag.ISmartTagAction.VerbCaptionFromID
Get
Select
Case VerbID
Case
1 'visualizza il testo delle due caption
Return "E
mail"
Case
2
Return "Sito"
End
Select
End
Get
End Property
La proprietà VerbCount
Ritorna il numero delle voci.
Public ReadOnly Property VerbCount(ByVal SmartTagName
As String) As Integer Implements Microsoft.Office.Interop.SmartTag.ISmartTagAction.VerbCount
Get
'ritorna
il numero delle voci
If
(SmartTagName.Equals("urn:esempio-smarttag#SmartTagE
manuele")) Then
Return
2
End
If
End
Get
End Property
La proprietà VerbId
Questa proprietà ritorna l'indice della voce selezionata.
Public ReadOnly Property VerbID(ByVal SmartTagName
As String, ByVal VerbIndex As Integer) As Integer Implements Microsoft.Office.Interop.SmartTag.ISmartTagAction.VerbID
Get
'ritorna
l'indice della voce
Return
VerbIndex
End
Get
End Property
La proprietà VerbNameFromid
Questa proprietà ha il compito di assegnare ad ogni
singolo indice (voce di menu) un nome indentificativo.
Public ReadOnly Property VerbNameFromID(ByVal
VerbID As Integer) As String Implements Microsoft.Office.Interop.SmartTag.ISmartTagAction.VerbNameFromID
Get
'imposto
i vari id
Select
Case VerbID
Case
1
Return "sende
mail"
Case
2
Return "site"
End
Select
End
Get
End Property
|