TaskItems2.Add2 方法

TaskList 添加新的任务项。

命名空间:  EnvDTE80
程序集:  EnvDTE80(在 EnvDTE80.dll 中)

语法

声明
Function Add2 ( _
    Category As String, _
    SubCategory As String, _
    Description As String, _
    Priority As Integer, _
    Icon As Object, _
    Checkable As Boolean, _
    File As String, _
    Line As Integer, _
    CanUserDelete As Boolean, _
    FlushItem As Boolean, _
    AutoNavigate As Boolean _
) As TaskItem
TaskItem Add2(
    string Category,
    string SubCategory,
    string Description,
    int Priority,
    Object Icon,
    bool Checkable,
    string File,
    int Line,
    bool CanUserDelete,
    bool FlushItem,
    bool AutoNavigate
)
TaskItem^ Add2(
    [InAttribute] String^ Category, 
    [InAttribute] String^ SubCategory, 
    [InAttribute] String^ Description, 
    [InAttribute] int Priority, 
    [InAttribute] Object^ Icon, 
    [InAttribute] bool Checkable, 
    [InAttribute] String^ File, 
    [InAttribute] int Line, 
    [InAttribute] bool CanUserDelete, 
    [InAttribute] bool FlushItem, 
    [InAttribute] bool AutoNavigate
)
abstract Add2 : 
        Category:string * 
        SubCategory:string * 
        Description:string * 
        Priority:int * 
        Icon:Object * 
        Checkable:bool * 
        File:string * 
        Line:int * 
        CanUserDelete:bool * 
        FlushItem:bool * 
        AutoNavigate:bool -> TaskItem
function Add2(
    Category : String, 
    SubCategory : String, 
    Description : String, 
    Priority : int, 
    Icon : Object, 
    Checkable : boolean, 
    File : String, 
    Line : int, 
    CanUserDelete : boolean, 
    FlushItem : boolean, 
    AutoNavigate : boolean
) : TaskItem

参数

  • Category
    类型:String

    必选。 表示任务项的类别名称。

  • SubCategory
    类型:String

    必选。 表示任务项的子类别名称。

  • Description
    类型:String

    必选。 描述任务项。

  • Priority
    类型:Int32

    可选。 一个表示任务项优先级(高、中或低)的 vsTaskPriority 常数。 如果该值为 vsTaskPriorityHigh,则会在**“任务列表”**的第一列中显示感叹号图标。 如果该值为 vsTaskPriorityMedium,则什么也不显示。 如果该值为 vsTaskPriorityLow,则显示一个向下箭头图标。

  • Icon
    类型:Object

    可选。 确定表示新任务项的图标类型。 它只能设置为 vsTaskIcon 或 IPictureDisp。

  • Checkable
    类型:Boolean

    可选。 指示是否求任务项提供复选框,用户可以通过选择该复选框来指示任务已完成。 默认值为 false。

  • File
    类型:String

    可选。 指示与新任务项相关联的文件或路径。 默认值为空字符串 (""),如果使用此默认值,则 IsSettable(vsTaskListColumnFile) 返回 false。 文件名称可以是完整路径、相对路径或者只是一个文件名。 请注意,将文件或路径与项关联并不一定意味着它会执行任何操作。

  • Line
    类型:Int32

    可选。 指示源代码中与新任务项相关联的行。 默认值为 0,如果使用此默认值,则 IsSettable(vsTaskListColumnLine) 返回 false。 请注意,将行号与项关联并不一定意味着它会执行任何操作。

  • CanUserDelete
    类型:Boolean

    可选。 指示当在环境中选定新任务项时,用户是否可通过按 Delete 删除该项。 默认值为 true。

  • FlushItem
    类型:Boolean

    可选。 指示新项在**“任务列表”中是否立即可见。 当 FlushItem 设置为 true 时,在调用 Add 后,会立即更新“任务列表”。 当 FlushItem 设置为 false 时,在完成所有更新后,才会更新“任务列表”。 false 设置主要用于在向“任务列表”**中同时添加很多项时改善性能。 默认值为 true。

  • AutoNavigate
    类型:Boolean

    可选。 指示 TaskItem 是否启用 AutoNavigate 功能。 当此选项设置为 true 时,AutoNavigate 为启用;当此选项设置为 false 时,AutoNavigate 为禁用。

返回值

类型:TaskItem
一个 TaskItem 对象。

备注

添加位图时,RGB 色 0x0000FF00(绿色)是透明的。 您的图片中所有使用此值的地方都将是透明的,**“任务列表”**可以透视。

位图的宽和高必须是 16 x 16 像素。

如果使用 IPictureDisp,PICTYPE 参数必须设置为 IconBitmapMetafilesUninitializedNone 的设置不能正常工作。

示例

此示例通过使用 Add2 方法向任务列表中添加两个任务项,并在消息框中显示它们的某些属性。 有关如何作为外接程序运行此示例的更多信息,请参见 如何:编译和运行自动化对象模型代码示例

Imports EnvDTE
Imports EnvDTE80
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)
    TaskItemsAdd2Example(_applicationObject)
End Sub
Sub TaskItemsAdd2Example(ByVal dte As DTE2)
    Dim win As Window = _
    _applicationObject.Windows.Item(Constants.vsWindowKindTaskList)
    Dim TL As TaskList = CType(win.Object, TaskList)
    Dim TLItem As TaskItem
    Dim TLItems As TaskItems2
    TLItems = CType(TL.TaskItems, TaskItems2)
    ' Add a couple of tasks to the Task List using Add2.
    TLItem = TLItems.Add2(" ", " ", "Test task 1." _
    , vsTaskPriority.vsTaskPriorityHigh, vsTaskIcon.vsTaskIconUser _
    , True, , 10, , , False)
        TLItem = TLItems.Add2(" ", " ", "Test task 2." _
    , vsTaskPriority.vsTaskPriorityLow, vsTaskIcon.vsTaskIconComment _
    , , , 20, , , False)
    ' List the total number of task list items after adding the new 
    ' task items.
        MsgBox("Task Item 1 description: "  _
    & TLItems.Item(2).Description)
    MsgBox("Total number of task items: " & TLItems.Count)
    ' Remove the second task item.
    ' The items list in reverse numeric order.
    MsgBox("Deleting the second task item")
    TLItems.Item(1).Delete()
    MsgBox("Total number of task items: " & TLItems.Count)
End Sub
using EnvDTE;
using EnvDTE80;
using System.Windows.Forms;
public void OnConnection(object application, 
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    TaskItems2Add2Example(_applicationObject);
}
public void TaskItems2Add2Example(DTE2 dte)
{
    Window2 win = (Window2)_applicationObject.Windows.Item
(Constants.vsWindowKindTaskList);
    TaskList TL = (TaskList)win.Object;
    TaskItem TLItem;
    TaskItems2 TLItems;
    TLItems = (TaskItems2)TL.TaskItems;
    // Add a couple of tasks to the Task List.
    TLItem = TLItems.Add2("MyTask", "MyTask1", "Test task 1."
, 1, vsTaskIcon.vsTaskIconUser, true,null,10,true,true,true);
TLItem = TLItems.Add2("MyTask", "MyTask1", "Test task 2."
, 2, vsTaskIcon.vsTaskIconComment, true, null, 20, true, true,false);
    // List the total number of task list items after adding the new
    // task items.
    MessageBox.Show("Task Item 1 description: " 
+ TLItems.Item(2).Description);
    MessageBox.Show("Total number of task items: " 
+ TLItems.Count.ToString());
    // Remove the second task item.
    // The items list in reverse numeric order.
    MessageBox.Show("Deleting the second task item");
    TLItems.Item(1).Delete();
    MessageBox.Show("Total number of task items: " + TLItems.Count);
}

.NET Framework 安全性

请参阅

参考

TaskItems2 接口

EnvDTE80 命名空间