| Author: |
Carlos J. Quintero (Microsoft MVP) |
Applies to: |
Microsoft Visual Studio 2005 |
| Date: |
March 2009 |
|
Microsoft Visual Studio 2008 |
| |
|
|
|
Introduction
When you call ProjectItem.Open(EnvDTE.Constants.vsext_vk_Designer) from a macro
or add-in, you get an EnvDTE.Window which is not visible (you would need to call
Window.Visible = True). However, that statement restores the IDE from a minimized
state. This is undesirable in the following scenario: an add-in executes an
operation that reviews the controls of each form of a project. To do this, it opens the
designer windows without making them visible (to get the EnvDTE.Window and then
to cast the Window.Object property to IDesignerHost). If the operation is long
because there are many forms in the project, the user may want to minimize the
IDE to use other applications while the operation is performed. Due to this bug,
the IDE is restored each time that a new form is processed.
Cause
This is a bug introduced in Visual Studio 2005. It didn't happen in VS.NET 2003.
More Information
Steps to reproduce the problem:
- Create a Visual Studio 2005/2008 macro with this code:
| Language: VB.NET | Copy Code (IE only) |
Public Sub Macro1()
DTE.MainWindow.WindowState = vsWindowState.vsWindowStateMinimize
For Each project As Project In DTE.Solution.Projects()
OpenAndCloseDesignerWindows(project.ProjectItems)
Next
End Sub
Private Sub OpenAndCloseDesignerWindows(ByVal projectItems As ProjectItems)
Dim projectItem As ProjectItem
Dim window As Window
If Not (projectItems Is Nothing) Then
For Each projectItem In projectItems
Try
If projectItem.Kind = Constants.vsProjectItemKindPhysicalFolder Then
OpenAndCloseDesignerWindows(projectItem.ProjectItems)
Else
Select Case projectItem.Properties.Item("SubType").Value.ToString
Case "Form", "UserControl"
window = projectItem.Open(Constants.vsViewKindDesigner)
If Not (window Is Nothing) Then
window.Close(vsSaveChanges.vsSaveChangesNo)
If DTE.MainWindow.WindowState <> vsWindowState.vsWindowStateMinimize Then
MsgBox("The IDE has been restored! It will be minimized again")
DTE.MainWindow.WindowState = vsWindowState.vsWindowStateMinimize
End If
End If
End Select
End If
Catch ex As Exception
' Ignore
End Try
Next
End If
End Sub
- Load a Windows Forms project with several forms and run the macro from the
Macro Explorer.
- The IDE is minimized when the macro is executed, but it is restored each time
that a form is processed.
Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this
|