What Is a Smart

Smart tags are a Microsoft Office feature that can be programmed to recognize certain text and then present users with actions they can take related to the text. Smart tags implement two interfaces: ISmartTagRecognizer (the recognizer) and ISmartTagAction (the action).

Microsoft Word and Excel include a number of built-in smart tags. For example, if you type a person's first and last names into a Word document, Word places a red dotted line underneath the name, indicating that a smart tag has been created for this text, which is recognized as a name. When you move your cursor over the name, a Smart Tag Actions button with an information symbol appears above the name. When the Smart Tag Actions button is selected, a drop-down arrow is revealed. When you click the drop-down arrow, a list appears showing a number of actions associated with the smart tag, such as sending an e-mail or scheduling a meeting, as shown in Figure 9.1.

Figure 9.1. Built-in smart tag in Word

Users can turn off these smart tag options in the AutoCorrect Options dialog box. To open this dialog box, click AutoCorrect Options in the Tools menu. On the Smart Tags tab are two options you should be aware of. The first is the Label Text With Smart Tags check box. When this option is selected, the dotted line will appear under recognized words. The second is the Show Smart Tag Actions Buttons check box. When this check box is selected, recognized words display the Smart Tag Actions button whenever the cursor is above the recognized word. If these options are not selected, the smart tags will not be visible to end users. Figure 9.2 shows these options.

Because these settings can be changed by the end user, you might want to add code to the Startup event handler of ThisDocument, as shown in Listing 9.1. This code ensures that these settings are turned on when you provide smart tags as part of your solution.

Figure 9.2. AutoCorrect options for smart tags in Word

Listing 9.1. Ensuring that Word smart tag options are turned on at startup

Private Sub ThisDocument_Startup(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Startup

Me.Application.Options.LabelSmartTags = True Me.Application.Options.DisplaySmartTagButtons = True

End Sub

Rather than change a user's settings (this is not always a good thing to do!), you should probably prompt users to let them know that they need to have these settings turned on to use your solution. You'll see an example in Listing 9.2.

Excel also provides a number of built-in smart tags. For example, text recognized, such as a date in an Excel cell, displays a small triangle in the lower-right corner of the cell. In our example, users can choose an action associated with the recognized date; in this case, they can open the Outlook calendar to the date, as shown in Figure 9.3.

A

B

C

D

1

2

3

4

5

6

®

7

5/1 /2006j

8

Date: 5/1/2006

-

g

10

Show my Calendar

11

Remove this Smart Tag Stop Recognizing "5/1/2006" ►

12

13

14

Smart Tag Options...

Id

1K

Figure 9.3. Built-in smart tag in Excel

In Excel, the smart tag settings are also found in the AutoCorrect options, as shown in Figure 9.4. Selecting the Label Data With Smart Tags check box causes Excel to recognize the term. You can set the

Figure 9.4. Smart tag options in Excel

Show Smart Tags As combo box to display any of three combinations: the smart tag indicator (the small triangle) and the Smart Tag Actions button; the button alone; or neither.

Because users can change these options, you should check to see whether these options are set and, if they aren't, let users change these settings, as shown in Listing 9.2. Be sure to restore users' options when the solution is closed.

Listing 9.2. Ensuring that Excel smart tag options are turned on at startup

Private Sub ThisWorkbook_Startup(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Me.Startup

If Application.AutoCorrect.DisplayAutoCorrectOptions = _ False Then

If MsgBox("This document uses smart tags, " _

& "which are currently disabled. Do you want to " _ & " enable smart tags?", MsgBoxStyle.YesNo) = _ MsgBoxResult.Yes Then

Application.AutoCorrect.DisplayAutoCorrectOptions = _ True

Me.SmartTagOptions.DisplaySmartTags = _

Excel.XlSmartTagDisplayMode.xlIndicatorAndButton

End If End If

End Sub

Both Word and Excel have a number of built-in recognizers that you can enable or disable. In addition, you can create your own document-level smart tags with VSTO. These smart tags differ from Office smart tags in that they are available only to the specific document or workbook in which you define them. Although you can create application-level smart tags using a COM or managed shared add-in, VSTO supports only document-level smart tags, and this type of smart tag is the focus of this chapter.

0 0

Post a comment