TaskItems2.Add 方法 (String, String, String, vsTaskPriority, Object, Boolean, String, Int32, Boolean, Boolean)

TaskList 添加新的任务项。

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

语法

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

参数

  • Category
    类型:System.String
    必选。表示任务项的类别名称。
  • SubCategory
    类型:System.String
    必选。表示任务项的子类别名称。
  • Icon
    类型:System.Object
    可选。确定表示新任务项的图标类型。它只能设置为 vsTaskIcon 或 IPictureDisp。
  • Checkable
    类型:System.Boolean
    可选。指示是否求任务项提供复选框,用户可以通过选择该复选框来指示任务已完成。默认值为 false。
  • File
    类型:System.String
    可选。指示与新任务项相关联的文件或路径。默认值为空字符串 (""),如果使用此默认值,则 IsSettable(vsTaskListColumnFile) 返回 false。文件名称可以是完整路径、相对路径或者只是一个文件名。请注意,将文件或路径与项关联并不一定意味着它会执行任何操作。
  • Line
    类型:System.Int32
    可选。指示源代码中与新任务项相关联的行。默认值为 0,如果使用此默认值,则 IsSettable(vsTaskListColumnLine) 返回 false。请注意,将行号与项关联并不一定意味着它会执行任何操作。
  • CanUserDelete
    类型:System.Boolean
    可选。指示当在环境中选定新任务项时,用户是否可通过按 Delete 删除该项。默认值为 true。
  • FlushItem
    类型:System.Boolean
    可选。指示新项在**“任务列表”中是否立即可见。当 FlushItem 设置为 true 时,在调用 Add 后,会立即更新“任务列表”。当 FlushItem 设置为 false 时,在完成所有更新后,才会更新“任务列表”。false 设置主要用于在向“任务列表”**中同时添加很多项时改善性能。默认值为 true。

返回值

类型:EnvDTE.TaskItem
TaskItem 对象。

备注

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

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

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

示例

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

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)
    TaskItems2Example(_applicationObject)
End Sub
Sub TaskItems2Example(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.
    TLItem = TLItems.Add(" ", " ", "Test task 1.", _
     vsTaskPriority.vsTaskPriorityHigh, vsTaskIcon.vsTaskIconUser _
    , True, , 10, , )
     TLItem = TLItems.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: " & 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;
    TaskItems2Example(_applicationObject);
}
public void TaskItems2Example(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.Add("MyTask", "MyTask1", "Test task 1."
, vsTaskPriority.vsTaskPriorityHigh, vsTaskIcon.vsTaskIconUser
, true,null,10,true,true );
    TLItem = TLItems.Add("MyTask", "MyTask1", "Test task 2."
, vsTaskPriority.vsTaskPriorityLow, vsTaskIcon.vsTaskIconComment
, true, null, 20, true, true);
    // 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 接口

Add 重载

EnvDTE80 命名空间