问题
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.
回答1:
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.
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
Here's the MSDN page.
Here's a related post showing the c# framework.
来源:https://stackoverflow.com/questions/48686672/how-do-i-listen-for-a-project-change-event-from-an-ms-project-vsto-add-in