Click here to Skip to main content
13,293,369 members (54,458 online)
Click here to Skip to main content
Add your own
alternative version


36 bookmarked
Posted 19 Apr 2005

VS.NET Change Case Add-In

, 19 Apr 2005
Rate this:
Please Sign up or sign in to vote.
This article describes step by step creation of an Add-In for VS.NET.

Sample Image - ChangeCaseAddIn.jpg


In this article, I would create an add-in to toggle the case of selected text. It explains both options of accessing the functionality from the Tools menu or the context menu.


I was really fantasized by the Add-Ins which are available on the net for Visual Studio .NET. I have been using VSPropertyGenerator for a long time and as a programmer I was always curious to know how it worked. I searched on the internet and was able to find the information but in a scattered way. So, it took me a while to write my own Add-In. To help others, I would explain step by step how to create an Add-In.

Note: Visual Studio provides the namespaces Microsoft.Office.Core, Extensibility and EnvDTE to access the DTE of Visual Studio.


Open Visual Studio .NET and create a new project. In the New Project window, select “Other projects-> Extensibility projects”, and select template as “Visual Studio .NET AddIns”.

Give a name, say “ChangeCaseAddIn”.

Sample screenshot

Press OK. Select the items in wizard as shown below:

Sample screenshot

Sample screenshot

Select Options -> “Tools” to display it in menu:

Sample screenshot

Click Next and press OK. You would have two projects names: “ChangeCaseAddIn” and “ChangeCaseAddInSetup”.

Now, open the connect.cs class in the ChangeCaseAddIn project. In the OnConnection method, add the following code:

if(connectMode == Extensibility.ext_ConnectMode.ext_cm_Startup)
    object []contextGUIDS = new object[] { };
    Commands commands = applicationObject.Commands;
    _CommandBars commandBars = applicationObject.CommandBars;
     // Enable this code if wants to display menu item in "Tools"
     //CommandBar commandBar = (CommandBar)commandBars["Tools"];
     // Enable this code to display options as context menu
     CommandBar commandBar = (CommandBar)commandBars["Code Window"];
     Command command = commands.AddNamedCommand(addInInstance, "ToggleCase", 
        "Toggle Case", "Changes selected text case", true, 59, ref contextGUIDS, 
     CommandBarControl commandBarControl = command.AddControl(commandBar, 1);
    catch(System.Exception /*e*/)

This code helps to add the toggle case in the “Tools” menu or in the context menu.

Modify QueryStatus method to:

if(commandName == "ChangeCaseAddIn.Connect.ToggleCase")
  status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | 

To display the menu item: change EXEC method to toggle the selected text case.

    TextDocument doc = 
       applicationObject.ActiveDocument.Object("TextDocument") as TextDocument;
    string text = doc.Selection.Text;
    if(commandName == "ChangeCaseAddIn.Connect.ToggleCase")
      // Toggle case
      if(text == text.ToLower(System.Globalization.CultureInfo.CurrentCulture))
       doc.Selection.Text = 
       doc.Selection.Text = 

When you build and create a setup for this application, you can only see a new option called “ToggleCase” in the context menu and without any image.

Sample screenshot

To display an image against it, you need to assign a bitmap to the add-in using a resource file. To do so, add a new project to this solution for displaying the icon\BMP against the menu item. Add a new project, select “Win32 project”:

Sample screenshot

Right click on “Resource File” folder in this project and select “Add New Item”. Add a new resource file to this folder:

Sample screenshot

Now, double click on the resource file added to the Open Resource view. In Resource view, right click on the resource file and add a bitmap using “Add Resource” option. Select the BMP file and change the property “ID” from IDB_BITMAP1 to 1 and language as US English.

Now, open the connect.cs class in the ChangeCaseAddIn project. In OnConnection method, modify the following code:

Command command = commands.AddNamedCommand(addInInstance, "ToggleCase", 
  "Toggle Case", "Changes selected text case", false, 1, ref contextGUIDS, 
  (int)vsCommandStatus.vsCommandStatusSupported + 

Note we changed “true” to “false” and 59 to 1 in the AddNamedCommand method to display the bitmap created above.

Create setup again. Right click on the ChangeCaseAddInSetup project and select “File View”. Right click on the application folder and create a new folder named “1033” (for English language). Right click application folder again and select “Add Project Output”. On the dialog box, select “ChangeCaseAddIn” primary output.

Right click on the newly created folder “1033” and select primary project output of “ChangeCaseAddInUI”.

Sample screenshot

Right click on the ChangeCaseAddInSetup project again and select “Registry”. Add to a new string values to the “AddIn” key for handling bitmap displaying.

  • SatelliteDLLName: Add the VC++ DLL name and path.
  • SatelliteDLLPath: Path to DLL (user [TARGETDIR]).

Sample screenshot

Rebuild the solution and install the application.

Open a new project and you would see “ToggleCase” in the context menu. You could now select any text and toggle the case (upper and lower) by clicking on this item.

Sample screenshot

Modifying “OnConnection” method of the Connect class in ChangeCaseAddIn project would display this item in the Tools menu rather than in the context menu.

Sample screenshot


This concludes the article to create an add-in for Visual Studio .NET. I tried to explain in detail as much I could. For any apprehensions, please drop a message.


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


About the Author

S Sansanwal
Australia Australia
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionHow to add submenu to 'Code Window' menu? Pin
Behzad Ebrahimi17-Jul-08 20:16
memberBehzad Ebrahimi17-Jul-08 20:16 
GeneralTip Pin
Darth_Sulfur16-Jul-05 17:00
memberDarth_Sulfur16-Jul-05 17:00 
GeneralGood article Pin
julio36111-Jun-05 15:13
memberjulio36111-Jun-05 15:13 
GeneralExisting keyboard functionality... Pin
Gordon Mackie27-Apr-05 1:37
memberGordon Mackie27-Apr-05 1:37 
GeneralRe: Existing keyboard functionality... Pin
S Sansanwal18-May-05 12:20
memberS Sansanwal18-May-05 12:20 
GeneralFix formatting Pin
leppie19-Apr-05 20:28
memberleppie19-Apr-05 20:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 19 Apr 2005
Article Copyright 2005 by S Sansanwal
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid