0

我正在尝试在 Visual Studio 2012 中创建一个加载项,该加载项将在执行程序后执行操作。这需要我知道何时进入设计模式。我有下面的代码,但它是在 C# 中,我在 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# 版本那样看到弹出消息框并通知已进入设计模式。有小费吗?

谢谢。

4

1 回答 1

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
于 2013-07-31T18:45:29.323 回答