Share via


HOW TO:控制工作清單

您可以使用 Automation,藉以控制 [工作清單] 及其內容。 在 Visual Studio Automation 模型中,它是以下列物件和集合來表示。

物件名稱

描述

TaskList 物件

表示 [工作清單]。

TaskItems 集合

表示 [工作清單] 中的所有工作。

TaskItem 物件

表示 [工作清單] 中的單一工作項目。

TaskListEvents 物件

可讓您回應在 [工作清單] 中發生的事件。

使用這些物件和集合,您可以:

  • 建立工作項目並將其加入至 [工作清單] 中 (Add 方法),或是從 [工作清單] 中刪除工作項目 (Delete 方法)。

  • 取得目前在 [工作清單] 中的項目 (Select 方法)。

  • 顯示與工作項目有關聯的文件 (Navigate 方法)。

  • 選取工作項目 (Select 方法)。

  • 在加入、移除、修改或選取工作項目時回應 (TaskAddedTaskRemovedTaskModifiedTaskNavigated 事件)。

除了控制 [工作清單] 的內容外,您也可以控制視窗的特性,例如寬度和高度。 如需詳細資訊,請參閱HOW TO:變更視窗特性

注意事項注意事項

根據您目前使用的設定或版本,您所看到的對話方塊與功能表指令可能會與 [說明] 中描述的不同。 使用 [一般開發設定] 開發了這些程序。 若要變更設定,請從 [工具] 功能表中選擇 [匯入和匯出設定]。 如需詳細資訊,請參閱 使用設定

範例

在下列增益集 (Add-In) 範例中,會示範如何參考及使用 [工作清單] Automation 模型的各個成員。 這個範例會在 [工作清單] 中加入新的工作、列出工作數目,然後刪除其中一個工作。 執行下列範例之前,請選取 [檢視] 功能表中的 [工作清單]。 工作會顯示在 [增益集和巨集] 分類中。

Public Sub OnConnection(ByVal application As Object, ByVal _
  connectMode As ext_ConnectMode, ByVal addInInst As Object, _
  ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    ' Pass the applicationObject member variable to the code example.
    TaskListExample(_applicationObject)
End Sub

Sub TaskListExample(ByVal dte As DTE2)
    Dim tl As TaskList = dte.ToolWindows.TaskList
    Dim tlItem As TaskItem

    ' Add a couple of tasks to the Task List.
    tlItem = tl.TaskItems.Add(" ", " ", "Test task 1.", _
      vsTaskPriority.vsTaskPriorityHigh, vsTaskIcon.vsTaskIconUser, _
      True, , 10, , )
    tlItem = tl.TaskItems.Add(" ", " ", "Test task 2.", _
      vsTaskPriority.vsTaskPriorityLow, vsTaskIcon.vsTaskIconComment, _
      , , 20, , )

    ' List the total number of task list items after adding the new 
    ' task items.
    MsgBox("Task Item 1 description: " & _
      tl.TaskItems.Item(2).Description)
    MsgBox("Total number of task items: " & tl.TaskItems.Count)

    ' Remove the second task item. The items list in reverse numeric 
    ' order.
    MsgBox("Deleting the second task item")
    tl.TaskItems.Item(2).Delete()
    MsgBox("Total number of task items: " & tl.TaskItems.Count)
End Sub
using System.Windows.Forms;
public void OnConnection(object application, ext_ConnectMode   
connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    TaskListExample(_applicationObject);
}

public void TaskListExample(DTE2 dte)
{
    TaskList tl = (TaskList)dte.ToolWindows.TaskList;
    TaskItem tlItem;
    
    // Add a couple of tasks to the Task List.
    tlItem = tl.TaskItems.Add(" ", " ", "Test task 1.",  
      vsTaskPriority.vsTaskPriorityHigh, vsTaskIcon.vsTaskIconUser, 
      true, "", 10, true, true);
    tlItem = tl.TaskItems.Add(" ", " ", "Test task 2.", 
      vsTaskPriority.vsTaskPriorityLow, vsTaskIcon.vsTaskIconComment, 
      true, "", 20, true,true);

    // List the total number of task list items after adding the new 
    // task items.
    System.Windows.Forms.MessageBox.Show("Task Item 1 description: 
      "+tl.TaskItems.Item(2).Description);
    System.Windows.Forms.MessageBox.Show("Total number of task items: 
      "+tl.TaskItems.Count);

    // Remove the second task item. The items list in reverse numeric 
    // order.
    System.Windows.Forms.MessageBox.Show("Deleting the second task 
      item");
    tl.TaskItems.Item(2).Delete();
    System.Windows.Forms.MessageBox.Show("Total number of task items: 
      "+tl.TaskItems.Count);
}

請參閱

工作

HOW TO:變更視窗特性

HOW TO:建立增益集

逐步解說:建立精靈

參考

工作清單 (Visual Studio)

概念

Automation 物件模型圖表

其他資源

建立和控制環境視窗

建立增益集和精靈

Automation 與擴充性參考