Condividi tramite


ImportsEvents Interface

Provides access to events that are raised when a project Imports statement is added to or deleted from a Visual Basic project. Use this object for functionality and refer to ImportsEventsClass for this object’s documentation.

Namespace:  VSLangProj
Assembly:  VSLangProj (in VSLangProj.dll)

Syntax

'Declaration
<GuidAttribute("037AD859-7A75-4CF3-8A38-83D6E045FEE3")> _
Public Interface ImportsEvents _
    Inherits _ImportsEvents, _dispImportsEvents_Event
[GuidAttribute("037AD859-7A75-4CF3-8A38-83D6E045FEE3")]
public interface ImportsEvents : _ImportsEvents, 
    _dispImportsEvents_Event
[GuidAttribute(L"037AD859-7A75-4CF3-8A38-83D6E045FEE3")]
public interface class ImportsEvents : _ImportsEvents, 
    _dispImportsEvents_Event
[<GuidAttribute("037AD859-7A75-4CF3-8A38-83D6E045FEE3")>]
type ImportsEvents =  
    interface 
        interface _ImportsEvents 
        interface _dispImportsEvents_Event 
    end
public interface ImportsEvents extends _ImportsEvents, _dispImportsEvents_Event

The ImportsEvents type exposes the following members.

Methods

  Name Description
Public method add_ImportAdded Infrastructure. Microsoft Internal Use Only. (Inherited from _dispImportsEvents_Event.)
Public method add_ImportRemoved Infrastructure. Microsoft Internal Use Only. (Inherited from _dispImportsEvents_Event.)
Public method remove_ImportAdded Infrastructure. Microsoft Internal Use Only. (Inherited from _dispImportsEvents_Event.)
Public method remove_ImportRemoved Infrastructure. Microsoft Internal Use Only. (Inherited from _dispImportsEvents_Event.)

Top

Events

  Name Description
Public event ImportAdded Infrastructure. Microsoft Internal Use Only. (Inherited from _dispImportsEvents_Event.)
Public event ImportRemoved Infrastructure. Microsoft Internal Use Only. (Inherited from _dispImportsEvents_Event.)

Top

Remarks

The ImportsEvents object may be accessed from either the VSProject object or the DTE object. Each project, through the VSProject object, has an ImportsEvents object providing access to the events of that project. The ImportsEvents object of the DTE object may be used to connect to events of individual projects or to events of all Visual Basic projects in the solution.

Examples

The following two examples use the late-bound VBImportsEvents property to connect to Visual Basic project events.

There are two late-bound methods for handling events. The first method allows you to connect to events for a particular project and requires the Option Strict Off statement to compile. This method returns an error if the parameter to the VBImportsEvents call is not of type Project. The parameter to VBImportsEvents is optional. If it is omitted, events for all the Visual Basic projects in the solution are received.

' Macro editor
Option Strict Off
Imports VSLangProj
Dim WithEvents importEvents As ImportsEvents
Sub ConnectAllImportEvents()
   Dim proj As Project = DTE.Solution.Projects.Item(1)
   importEvents = DTE.Events.VBImportsEvents(proj)
End Sub 

Public Sub importEvents_ImportAdded(ByVal bstrImport As String) _
Handles importEvents.ImportAdded
   MsgBox(bstrImport)
End Sub

The second late-bound method allows you to add event-handling methods for events in all the projects in the solution. This method does not offer a way to filter events for only a particular project. It will compile with Option Strict On.

' Macro editor
Imports VSLangProj
Dim WithEvents importEvents As ImportsEvents
Sub ConnectProjectImportEvents()
   importEvents = CType(DTE.Events.GetObject("VBImportsEvents"), _
      ImportsEvents)
End Sub

Public Sub importEvents_ImportAdded(ByVal bstrImport As String) _
Handles importEvents.ImportAdded
   MsgBox(bstrImport)
End Sub

See Also

Reference

VSLangProj Namespace