如何从 MS Project VSTO 加载项监听项目变更事件? [英] How do I listen for a Project Change event from an MS Project VSTO Add-in?

查看:20
本文介绍了如何从 MS Project VSTO 加载项监听项目变更事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的外接程序有一个应用程序事件 ProjectBeforeTaskChange,可从 ThisAddIn 类获得.我需要的是 ProjectAfterTaskChange 事件,但这并不存在.有没有办法从应用程序级加载项中侦听 Project Change 事件?

My Add-in has an application event ProjectBeforeTaskChange that is available from the ThisAddIn class. What I need is a ProjectAfterTaskChange event, but that doesn't exist. Is there a way to listen for the Project Change event from an application level add-in?

我的最终目标是在特定文本字段更改时设置三个数字字段.

My end goal is to set three number fields when a specific text field changes.

推荐答案

ProjectBeforeTaskChange 是用于监视字段更改的正确事件.Before"一词指的是处理程序可以通过将 Cancel 参数设置为 True 来阻止更改.当用户对任务字段进行更改时触发该事件.

ProjectBeforeTaskChange is the correct event to use to monitor field changes. The word "Before" refers to the fact that the handler can prevent the change by setting the Cancel argument to True. The event is triggered when the user makes a change to a task field.

这是一个 vb.net 示例,它在 Text1 字段更改时递增 Number1 和 Number2 字段:

Here's a vb.net example that increments the Number1 and Number2 fields whenever the Text1 field changes:

Private Sub Application_ProjectBeforeTaskChange(tsk As MSProject.Task, Field As MSProject.PjField, NewVal As Object, ByRef Cancel As Boolean) Handles Application.ProjectBeforeTaskChange

    If Field = MSProject.PjField.pjTaskText1 Then
        Select Case NewVal
            Case Is = "In-work": tsk.Number1 = 50
            Case Is = "Complete": tsk.Number1 = 100
            Case Else: tsk.Number1 = 0
        End Select
    End If
End Sub

这是 MSDN 页.

这是一个相关帖子,展示了 c#框架.

Here's a related post showing the c# framework.

这篇关于如何从 MS Project VSTO 加载项监听项目变更事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆