Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Close the Start Page Add-In for Visual Studio

0.00/5 (No votes)
26 Mar 2009 1  
A custom Add-In to close the Start Page in Visual Studio after you open your project

Introduction

This is a simple Visual Studio add-in that will automatically close the Start page when you open your solution in Visual Studio.

I love Visual Studio and the Start Page but why there isn't an option to close the Start Page after you open your solution is beyond me. And if you ever need to re-open the Start Page, simply go to the "View" menu and select "Other Windows" and click "Start Page".

Using the Code

To build this application from scratch go into Visual Studio and select "New" Project. Then browse to "Other Project Types\Extensibility" and select "Visual Studio Add-in". Then name your project "StartPageCloser".

Next the Add-in Wizard will start and for this project, we will select C# code:

Next, only select Microsoft Visual Studio:

Give a good description of your Add-in:

Set your Add-in to load on Startup:

The About dialog box is optional. Then Click finish to start your new Add-in project.

Here is where you will need to add your code. Start by adding the private variables needed to capture the Open Solution event.  You can add this code at the top or the bottom of the Connect class. You should already be in the Connect class, if not then open the Connect.cs file.

    //
    // Private variables used to capture the Solution events
    //        
    private Events2 events; 
    private SolutionEvents solutionEvents;

Next go to the "OnConnection" event function and add the following code after the line:
_addInInstance = (AddIn)addInInst;

    // Capture our Events
    events = (Events2)_applicationObject.Events;
    solutionEvents = events.SolutionEvents;

    // Capture our Solution Opened Event
    solutionEvents.Opened += 
	new _dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened);        

Finally all you need to do is add your SolutionEvents_Opened function.

/// <summary>
/// Our Solution has been opened
/// </summary>
private void SolutionEvents_Opened()
{
	// Find the Start Page and Close it
	if (_applicationObject.Windows.Item
		(EnvDTE80.WindowKinds.vsWindowKindKindStartPage) != null)
	{
		// Close the Start Page
		_applicationObject.Windows.Item
			(EnvDTE80.WindowKinds.vsWindowKindKindStartPage).Close
			(vsSaveChanges.vsSaveChangesNo);
	}
}

You are now ready to compile and use your new Add-in.  After you compile, the Add-in will be added to your Visual Studio Addins folder.  This will point to the location of your Add-in DLL.  Feel free to change your project to "Release" mode when you are done.

Points of Interest

Sometimes, in order to compile your add-in you will need to close Visual Studio and make sure that it is not set to load your add-in on Startup by going to the "Tools" menu and "Add-in Manager..." and un-checking "Startup" for your add-in. Then close and re-open Visual Studio and open your project. Now you will be able to compile. Just remember to go back in and re-check "Startup" when you are done.

History

  • 26th March, 2009: Initial post 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here