共用方式為


VSProjectEvents2.ImportsEvents 屬性

取得可用來存取 Imports 物件事件的 ImportsEvents 物件。

命名空間:  VSLangProj80
組件:  VSLangProj80 (在 VSLangProj80.dll 中)

語法

'宣告
ReadOnly Property ImportsEvents As ImportsEvents
ImportsEvents ImportsEvents { get; }
property ImportsEvents^ ImportsEvents {
    ImportsEvents^ get ();
}
abstract ImportsEvents : ImportsEvents
function get ImportsEvents () : ImportsEvents

屬性值

型別:VSLangProj.ImportsEvents
ImportsEvents 物件。

備註

ImportsEvents 物件可用來存取 ImportAddedImportRemoved 這兩個事件。

範例

這個範例使用 Events 物件將事件處理方法連接到特定專案的 ImportAddedImportRemoved 事件。如需如何執行巨集範例的詳細資訊,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例

先開啟 Visual Basic、Visual C# 或 Visual J# 專案,再執行這個巨集。

' Macro editor
' This example adds event handlers to the two events in
' ImportsEvents.
Imports VSLangProj
Imports VSLangProj80
Sub ImportAdded(ByVal addedImport As String)
   MsgBox("The import '" & addedImport & "' was added.")
End Sub

Sub ImportRemoved(ByVal removedImport As String)
   MsgBox("The import '" & removedImport & "' was removed.")
End Sub

Sub ConnectImportsEvents()
   Dim proj As Project = DTE.Solution.Projects.Item(1)
   Dim vsproj As VSProject2 = CType(proj.Object, VSProject2)
   Dim impEvents As ImportsEvents = vsproj.Events.ImportsEvents
   AddHandler impEvents.ImportAdded, AddressOf ImportAdded
   AddHandler impEvents.ImportRemoved, AddressOf ImportRemoved
End Sub

.NET Framework 安全性

請參閱

參考

VSProjectEvents2 介面

ImportsEvents 多載

VSLangProj80 命名空間