Click here to Skip to main content
13,055,083 members (54,705 online)
Click here to Skip to main content
Add your own
alternative version


11 bookmarked
Posted 23 Oct 2008

Localizing Windows Forms programmatically using a VS2005 Add-in

, 23 Oct 2008
Rate this:
Please Sign up or sign in to vote.
This Visual Studio 2005 add-in is used to set the Localizable property of Windows forms programmatically.


I wanted to localize my Windows Forms programmatically, and had this problem for several months, and I couldn't find a possible solution in any of the forums. By simply creating a Visual Studio add-in, you can easily make your Windows forms localizable. And here, I publish the basic code for doing that, and this program only identifies Windows forms in the "Forms" directory in my folder structure. Thus, you may have to change the directory name where your forms exist.

Using the code

  1. First, you have to create a Visual Studio Extensibility Project using VS2005
  2. .

    You can get an idea of how to create an add-in here: Creating a tool window add-in with Visual Studio 2005.

  3. You have to follow the Wizard as it is for a basic add-in like the above, and you have to check the first check box in order to create a menu item in your Visual Studio Tools menu.
  4. After creating your add-in project using the Wizard, you can add the following code in the following method in the Connect class:
  5. public void Exec(string commandName, 
           vsCommandExecOption executeOption, ref object varIn,
           ref object varOut, ref bool handled) 
        handled = false; 
        if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault) 
            if(commandName == "MyAddin1.Connect.MyAddin1")
                handled = true; 
                    foreach (
                        EnvDTE.Project project in 
                        foreach (EnvDTE.ProjectItem item in project.ProjectItems) 
                            if (item.Name == "Forms") 
                                EnvDTE.ProjectItems forms = item.ProjectItems; 
                                foreach (EnvDTE.ProjectItem appForm in forms) 
                                    EnvDTE.Window appFormWindow = appForm.Open(
                                    if (appFormWindow != null) 
                                        appFormWindow.Visible = true; 
                                        IDesignerHost designerHost =
                                             appFormWindow.Object as IDesignerHost; 
                                        TypeDescriptionProvider p =
                                        ICustomTypeDescriptor t= 
                                        PropertyDescriptorCollection propCollection =
                                        PropertyDescriptor propDesc = 
                                          as PropertyDescriptor; 
                                        if (propDesc != null) 
                catch (Exception e) 
                    throw e; 
  6. Build your add-in.There you go! Now, open a Visual Studio project and find the newly created menu item under the Tools menu.
  7. If you have your forms under the “Forms” folder in your project, you will see your forms have got localized automatically.
  8. You will see some flickering during the execution because I am opening those forms in the Designer programmatically, so don’t worry about it.

Points of interest

Just thought of sharing this. Hope this will help for larger projects when you require to localize all your forms in projects.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
Sri Lanka Sri Lanka
I've been working as a Software Engineer for three years and really interested in Computer Science research activities.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 24 Oct 2008
Article Copyright 2008 by chandimacj
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid