Action 類別 (2007 系統)
更新:2007 年 11 月
表示 Microsoft Office Word 文件中的 Visual Studio Tools for Office 智慧標籤動作。
命名空間: Microsoft.Office.Tools.Word
組件: Microsoft.Office.Tools.Word.v9.0 (在 Microsoft.Office.Tools.Word.v9.0.dll 中)
語法
<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public Class Action _
Inherits ActionBase
Dim instance As Action
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public class Action : ActionBase
備註
動作是指系統在辨認智慧標籤的型別後,出現在智慧標籤快速鍵功能表上的可用選項。例如,人名型別字串的動作可能就是 [將名稱加入至連絡人資料夾]。如需 Visual Studio Tools for Office 中之智慧標籤的詳細資訊,請參閱智慧標籤架構。
範例
下列程式碼範例示範如何建立具備動作的智慧標籤。智慧標籤動作會修改在執行階段時動作的功能表標題,並且顯示所辨認文字的位置。若要測試範例,請在文件的不同位置中輸入文字「詞彙」和「辨認」,然後嘗試智慧標籤動作。
這是示範文件層級自訂的範例。
Private WithEvents displayAddress As Microsoft.Office.Tools.Word.Action
Private Sub AddSmartTag()
Dim smartTagDemo As New _
Microsoft.Office.Tools.Word.SmartTag( _
"www.microsoft.com/Demo#DemoSmartTag", _
"Demonstration Smart Tag")
' Specify the terms to recognize.
smartTagDemo.Terms.Add("term")
smartTagDemo.Terms.Add("recognize")
' Create the action.
displayAddress = New Microsoft.Office.Tools.Word.Action("To be replaced")
' Add the action to the smart tag.
smartTagDemo.Actions = New Microsoft.Office.Tools.Word.Action() { _
displayAddress}
' Add the smart tag.
Me.VstoSmartTags.Add(smartTagDemo)
End Sub
Private Sub OpenMessageBox_BeforeCaptionShow(ByVal sender As Object, _
ByVal e As Microsoft.Office.Tools.Word.ActionEventArgs) _
Handles DisplayAddress.BeforeCaptionShow
Dim clickedAction As Microsoft.Office.Tools.Word.Action = _
TryCast(sender, Microsoft.Office.Tools.Word.Action)
If clickedAction IsNot Nothing Then
clickedAction.Caption = "Display the location of " & e.Text
End If
End Sub
Private Sub DisplayAddress_Click(ByVal sender As Object, _
ByVal e As Microsoft.Office.Tools.Word.ActionEventArgs) _
Handles DisplayAddress.Click
Dim termStart As Integer = e.Range.Start
Dim termEnd As Integer = e.Range.End
MsgBox("The recognized text '" & e.Text & _
"' begins at position " & termStart & _
" and ends at position " & termEnd)
End Sub
private Microsoft.Office.Tools.Word.Action displayAddress;
private void AddSmartTag()
{
Microsoft.Office.Tools.Word.SmartTag smartTagDemo =
new Microsoft.Office.Tools.Word.SmartTag(
"www.microsoft.com/Demo#DemoSmartTag",
"Demonstration Smart Tag");
// Specify the terms to recognize.
smartTagDemo.Terms.Add("term");
smartTagDemo.Terms.Add("recognize");
// Create the action.
displayAddress = new Microsoft.Office.Tools.Word.Action("To be replaced");
// Add the action to the smart tag.
smartTagDemo.Actions = new Microsoft.Office.Tools.Word.Action[] {
displayAddress };
// Add the smart tag.
this.VstoSmartTags.Add(smartTagDemo);
displayAddress.BeforeCaptionShow += new
Microsoft.Office.Tools.Word.BeforeCaptionShowEventHandler(
displayAddress_BeforeCaptionShow);
displayAddress.Click += new
Microsoft.Office.Tools.Word.ActionClickEventHandler(
displayAddress_Click);
}
void displayAddress_BeforeCaptionShow(object sender,
Microsoft.Office.Tools.Word.ActionEventArgs e)
{
Microsoft.Office.Tools.Word.Action clickedAction =
sender as Microsoft.Office.Tools.Word.Action;
if (clickedAction != null)
{
clickedAction.Caption = "Display the location of " +
e.Text;
}
}
void displayAddress_Click(object sender,
Microsoft.Office.Tools.Word.ActionEventArgs e)
{
int termStart = e.Range.Start;
int termEnd = e.Range.End;
System.Windows.Forms.MessageBox.Show("The recognized text '" + e.Text +
"' begins at position " + termStart.ToString() +
" and ends at position " + termEnd.ToString());
}
繼承階層架構
System.Object
Microsoft.Office.Tools.ActionBase
Microsoft.Office.Tools.Word.Action
執行緒安全
這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。
請參閱
參考
Microsoft.Office.Tools.Word 命名空間