Ver versión en español    
 
Home
10 Reasons to use MZ-Tools
MZ-Tools 6.0 for VS.NET
Editions
Features
Online Documentation
MZ-Tools SDK
Download
Purchase
Version History (RSS)  
FAQ & Support
MZ-Tools 3.0 for VB6 & VBA
Features
Online Documentation
Download (freeware)
Donations (Paypal)
Version History (RSS)  
FAQ & Support
User Reviews
Community Place
Contact  
For Add-In Developers
About
   
 
User Testimonials

I'm an avid supporter of MZ-Tools. It's a product I couldn't do without and your level of support is outstanding.

Jan Hyde (Visual Basic MVP)

You will soon wonder how you ever lived without it.

Andy Maggs

More user reviews
 
HOWTO: Guessing the IDE mode (design, debug or run-time) from a Visual Studio add-in or macro

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio .NET 2002
Date: March 2007   Microsoft Visual Studio .NET 2003
      Microsoft Visual Studio 2005

Introduction

The IDE can be in one of these modes:

  • Design-time: this is the mode that you use to code or design your application.
  • Run-time: this is the mode when your application is running.
  • Debug-time: this is the mode when you debug your running application.

More Information

When you want to know programatically the mode of the IDE, you could think that you can use the EnvDTE.DTE.Mode property. However, the EnvDTE.vsIDEMode enum returned by that property has only two states (vsIDEModeDebug, vsIDEModeDesign), not three. Fortunately, you can use the EnvDTE.DebuggerEvents class, that provides the OnEnterDesignMode, OnEnterBreakMode and OnEnterRunMode events to track the current mode, assuming that the IDE is initially at design-time. So, you can use this code:

Public Class Connect
   Implements IDTExtensibility2
   Private Enum IDEMode
      Design = 1
      Debug = 2
      Run = 3
   End Enum
   Private _applicationObject As DTE2
   Private _IDEMode As IDEMode
   Private WithEvents _debuggerEvents As DebuggerEvents
   Public Sub OnConnection(ByVal application As Object, ByVal connectMode As ext_ConnectMode, _
       ByVal addInInst As Object, ByRef custom As Array) Implements IDTExtensibility2.OnConnection

      _applicationObject = CType(application, DTE2)
      _IDEMode = IDEMode.Design
      _debuggerEvents = _applicationObject.Events.DebuggerEvents

   End Sub
   Private Sub _debuggerEvents_OnEnterBreakMode(ByVal Reason As EnvDTE.dbgEventReason, _
      ByRef ExecutionAction As EnvDTE.dbgExecutionAction) Handles _debuggerEvents.OnEnterBreakMode

      _IDEMode = IDEMode.Debug

   End Sub
   Private Sub _debuggerEvents_OnEnterDesignMode(ByVal Reason As EnvDTE.dbgEventReason) _
      Handles _debuggerEvents.OnEnterDesignMode

      _IDEMode = IDEMode.Design

   End Sub
   Private Sub _debuggerEvents_OnEnterRunMode(ByVal Reason As EnvDTE.dbgEventReason) _
      Handles _debuggerEvents.OnEnterRunMode

      _IDEMode = IDEMode.Run

   End Sub
   ...
End Class

Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this

MZ-Tools 6.0 for Visual Studio .NET

You can code, design, locate code and document your apps much faster using VB.NET, C#, C++ or Visual J#:

Buy MZ-Tools Now Download MZ-Tools Demo

   Top