Logo
BUG: Document.ActiveWindow does not return always the active window in Visual Studio .NET

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio .NET 2002
Date: May 2004   Microsoft Visual Studio .NET 2003
Updated: February 2009    
       
Introduction

If you have a document with two windows open (such as a code window and a designer window), the Document.ActiveWindow property returns the first window which was opened for the document, not the active one.

Cause

This is a bug of Visual Studio .NET 2002/2003. It was fixed in Visual Studio 2005.

More Information

Steps to reproduce the problem:

  • Create a macro with this code:
Language: VB.NET   Copy Code Copy Code (IE only)
Sub MyMacro()

   Dim objDocument As Document
   Dim objWindow As Window

   objDocument = DTE.ActiveDocument

   If Not (objDocument Is Nothing) Then

      objWindow = objDocument.ActiveWindow

      If Not (objWindow Is Nothing) Then
         MessageBox.Show("Active Window: " & objWindow.Caption)
      End If

   End If

End Sub
  • In the IDE, create a Windows Form application and open the code window "Form1.vb" and the design window "Form1.vb [Design]", in this order.
  • Ensure that the "Form1.vb [Design]" window is the active one and execute the macro. Unexpectedly, you get that the active window is the code window "Form1.vb" instead of the design window "Form1.vb [Design]". This happens both in MDI mode and in Tabbed mode.


Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)


Top