2013-07-31 56 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."); 
    } 

我試圖將其轉換爲VB它相當於這導致

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 

Visual Studio中已標明「_debuggerEvents.OnEnterDesignMode」用一記「後期綁定的分辨率兩次出現的,可能會發生運行時錯誤。 「我沒有看到任何運行時錯誤,但是我從來沒有看到消息框會彈出通知,設計模式已經像C#版本那樣進入了。有小費嗎?

謝謝。

+0

使用'AddHandler'而不是使用指定的事件處理程序的'+ ='方法。 – Styxxy

+0

非常感謝! – janovak

+0

我將它添加爲答案。 – Styxxy

回答

1

使用AddHandler語句添加事件處理程序(這是在VB.NET中如何完成的方法之一)。

在你的情況,這將是:

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 
相關問題