2013-07-31 3 views
0

프로그램을 실행 한 후에 작업을 수행 할 추가 기능을 Visual Studio 2012에서 만들려고합니다. 설계 모드가 언제 입력되었는지 알 필요가 있습니다. 아래 코드는 작동하지만 C#에 있으며 VB.NET에서 작업하고 있습니다. 런타임 오류가 발생할 수 있습니다; Visual Studio가 디자인 모드에 들어 갔을 때를 결정하십시오. VB.NET

public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) 
    { 
     . 
     . 
     . 
     //Initialize event handlers for host 
     _debuggerEvents = _applicationObject.Events.DebuggerEvents; 
     _debuggerEvents.OnEnterDesignMode += new _dispDebuggerEvents_OnEnterDesignModeEventHandler(OnEnterDesignMode); 
    } 

    /// <summary>Handles when the host application object's debugger enters design mode (is done debugging).</summary> 
    /// <param name="reason">The reason that the host application object is entering design mode.</param> 
    public static void OnEnterDesignMode(dbgEventReason reason) 
    { 
     System.Windows.Forms.MessageBox.Show("ADD-IN DEBUG: Debugger enters design mode."); 
    } 

나는 메모와 함께 "_debuggerEvents.OnEnterDesignMode" "늦은 바인딩 해상도의 두 항목을 표시했다

Public Sub OnConnection(ByVal application As Object, ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, ByRef custom As Array) Implements IDTExtensibility2.OnConnection 
    . 
    . 
    . 
    ' Initialize event handlers for host 
    _debuggerEvents = _hostAppObj.Events.DebuggerEvents 
    _debuggerEvents.OnEnterDesignMode += New _dispDebuggerEvents_OnEnterDesignModeEventHandler(AddressOf _debuggerEvents.OnEnterDesignMode) 
End Sub 

Public Sub OnEnterDesignMode(ByVal reason As dbgEventReason) 
    System.Windows.Forms.MessageBox.Show("ADD-IN DEBUG: Debugger enters design mode.") 
End Sub 

비주얼 스튜디오 결과는 VB 동등한로 변환했습니다. " 런타임 오류는 보이지 않지만 C# 버전처럼 디자인 모드가 입력되었다는 알림 메시지 상자 팝업이 표시되지 않습니다. 어떤 팁?

감사합니다.

+0

사용. – Styxxy

+0

정말 고마워요! – janovak

+0

답변으로 추가했습니다. – Styxxy

답변

1

AddHandler 문을 사용하여 이벤트 처리기를 추가하십시오 (이것은 VB.NET에서의 처리 방법 중 하나입니다). 귀하의 경우에는

이는 다음과 같습니다`AddHandler` 대신에 이벤트 핸들러를 할당하는`+ = '방법을 사용

Public Sub OnConnection(ByVal application As Object, ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, ByRef custom As Array) Implements IDTExtensibility2.OnConnection 

    ' Initialize event handlers for host 
    _debuggerEvents = _hostAppObj.Events.DebuggerEvents 
    AddHandler _debuggerEvents.OnEnterDesignMode, AddressOf OnEnterDesignMode 
End Sub 

Public Sub OnEnterDesignMode(ByVal reason As dbgEventReason) 
    System.Windows.Forms.MessageBox.Show("ADD-IN DEBUG: Debugger enters design mode.") 
End Sub