|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThe aim of this article is to show you how to create a Visual Studio .NET 2005 add-in. This add-in will contain a ToolWindow, and a menu item under the View menu to display that ToolWindow. Should the window be closed, the menu item can be used to display it again. Creating the ProjectFirst off, create a new Extensibility project, with a Visual Studio Add-in type. This will display the wizard to guide you though the project creation. During the wizard, you will need to choose the following options:
A tools menu item will be created. The add-in will load only when the user selects the Load checkbox within the Add-in Manager dialog box.
The major page of the wizard is page 4, where you are able to select to create the tools menu item. Adding a Tool Window ControlA tool window is a user control hosted within an ActiveX container, so go ahead and add a new user control to the project. Mine is called To gain access to the IDE's "object" with your control, create a private field on the control of type Modifying the Add-in for the Tool WindowAlmost every other tool window in the IDE is opened through the View menu. The wizard generated code will place an item on the Tools menu for us, we need to change its location. In Connect.cs, you will find the code that creates the menu item and handles it. The try
{
ResourceManager resourceManager =
new ResourceManager("ToolWindowArticle.CommandBar",
Assembly.GetExecutingAssembly());
CultureInfo cultureInfo = new
System.Globalization.CultureInfo(_applicationObject.LocaleID);
string resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName,
"View");
toolsMenuName = resourceManager.GetString(resourceName);
}
catch
{
toolsMenuName = "View";
}
I removed the comments that the wizard generated, to keep the code short. Next, two private Window toolWindow;
private ToolWindowControl toolWindowControl;
As the tool window will not be created until after the IDE has loaded, the code should not reside within the same section of code as the menu item generation. At the end of the else if (connectMode == ext_ConnectMode.ext_cm_AfterStartup)
{
#region Load Tool Window
object programmableObject = null;
string guidString = "{9FFC9D9B-1F39-4763-A2AF-66AED06C799E}";
Windows2 windows2 = (Windows2)_applicationObject.Windows;
Assembly asm = Assembly.GetExecutingAssembly();
toolWindow = windows2.CreateToolWindow2(_addInInstance, asm.Location,
"ToolWindowArticle.ToolWindowControl",
"Pirate Window", guidString, ref programmableObject);
toolWindow.Visible = true;
toolWindowControl = (ToolWindowControl)toolWindow.Object;
toolWindowControl.ApplicationObject = _applicationObject;
#endregion
}
Getting the Menu Item to Display the ToolWindowThe window will display when the add-in is loaded; however, there is no way to re-display the window after it has been closed. The first click on the menu item loads the add-in; however, further clicks will not make it display again. A quick addition to the toolWindow.Visible = true;
ConclusionThis article has hopefully helped you create a Visual Studio add-in which displays a ToolWindow which is capable of interacting with the IDE. The View menu item which you created should re-display the window if it be closed. History
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||