如何:控制任务列表

**“任务列表”**及其内容可用自动化来控制。 它在 Visual Studio 自动化模型中由下列对象和集合表示。

对象名

说明

TaskList 对象

表示“任务列表”

TaskItems 集合

表示“任务列表”中的所有任务。

TaskItem 对象

表示“任务列表”中的一个任务项。

TaskListEvents 对象

使您可以响应“任务列表”中发生的事件。

通过使用这些对象和集合,您可以:

  • 创建任务项并将它添加到**“任务列表”(使用 Add 方法)或从“任务列表”**删除它(使用 Delete 方法)。

  • 获取当前在**“任务列表”**中的项(使用 Select 方法)。

  • 显示与任务项相关联的文档(使用 Navigate 方法)。

  • 选择任务项(使用 Select 方法)。

  • 添加、移除、修改或选择任务项时响应(TaskAddedTaskRemovedTaskModifiedTaskNavigated 事件)。

除了控制**“任务列表”**的内容之外,还可以控制其特性,如宽度和高度。 有关更多信息,请参见如何:更改窗口特性

提示

显示的对话框和菜单命令可能会与“帮助”中的描述不同,具体取决于您现用的设置或版本。 这些过程是在“常规开发设置”处于活动状态时开发的。 若要更改设置,请在“工具”菜单上选择“导入和导出设置”。 有关更多信息,请参见 使用设置

示例

下面的外接程序示例演示如何引用和使用**“任务列表”自动化模型的各种成员。 本示例向“任务列表”添加两个新任务,列出任务数,然后删除一个任务。 运行下面的示例前,请从“视图”菜单中选择“任务列表”。 相关任务显示在“外接程序和宏”**类别中。

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);
}

请参见

任务

如何:更改窗口特性

如何:创建外接程序

演练:创建向导

参考

任务列表 (Visual Studio)

概念

自动化对象模型图表

其他资源

创建和控制环境窗口

创建外接程序和向导

自动化与扩展性参考